7 Achegas daec26f2d8 ... 360a95c7aa

Autor SHA1 Mensaxe Data
  Hugo Sales 360a95c7aa [TESTS] Use custom test bootstrap to only to only setup the database once and wrap everything in a transaction that gets rolled back at the end of each test %!s(int64=2) %!d(string=hai) anos
  Hugo Sales b41de11364 [TESTS] Remove environment setup from script %!s(int64=2) %!d(string=hai) anos
  Hugo Sales 88e513c610 [TESTS] Make all services accessible in test environment %!s(int64=2) %!d(string=hai) anos
  Hugo Sales 5829e77edd [TESTS][TOOLS] Clarify make target names %!s(int64=2) %!d(string=hai) anos
  Hugo Sales 334de7c739 [TESTS] Speedup container startup %!s(int64=2) %!d(string=hai) anos
  Hugo Sales fe21796e79 [TESTS] Tweak tests %!s(int64=2) %!d(string=hai) anos
  Hugo Sales 789b1499c5 [TESTS] Fix deprecation warnings caused by removing xdebug %!s(int64=2) %!d(string=hai) anos

+ 14 - 11
Makefile

@@ -36,28 +36,31 @@ database-force-nuke:
 database-force-schema-update:
 	docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c "/var/www/social/bin/console doctrine:schema:update --dump-sql --force"
 
-tooling-docker: .PHONY
-	@cd docker/tooling && docker-compose up -d --build > /dev/null 2>&1
+tooling-docker-up: .PHONY
+	@sh -c 'if [ ! docker container inspect $(call translate-container-name,tooling_php_1) > /dev/null 2>&1 ]; then cd docker/tooling && docker-compose up -d --build > /dev/null 2>&1; fi'
 
-stop-tooling: .PHONY
+tooling-docker-down: .PHONY
 	cd docker/tooling && docker-compose down
 
-tooling-php-shell: tooling-docker
+test: tooling-docker-up
+	@docker exec $(call translate-container-name,tooling_php_1) /var/tooling/coverage.sh $(call args,'')
+
+test-database-force-nuke: tooling-docker-up
+	docker exec -it $(call translate-container-name,tooling_php_1) sh -c 'cd /var/www/social; bin/console doctrine:database:drop --force'
+
+tooling-php-shell: tooling-docker-up
 	docker exec -it $(call translate-container-name,tooling_php_1) sh
 
-test-accesibility: tooling-docker
+test-accesibility: tooling-docker-up
 	cd docker/tooling && docker-compose run pa11y /accessibility.sh
 
-test: tooling-docker
-	docker exec $(call translate-container-name,tooling_php_1) /var/tooling/coverage.sh $(call args,'')
-
-cs-fixer: tooling-docker
+cs-fixer: tooling-docker-up
 	@bin/php-cs-fixer $${CS_FIXER_FILE}
 
-doc-check: tooling-docker
+doc-check: tooling-docker-up
 	bin/php-doc-check
 
-phpstan: tooling-docker
+phpstan: tooling-docker-up
 	bin/phpstan
 
 remove-var:

+ 4 - 0
config/packages/test/config.yml

@@ -0,0 +1,4 @@
+services:
+  _defaults:
+    autowire: true
+    public: true

+ 2 - 13
docker/tooling/coverage.sh

@@ -2,16 +2,5 @@
 
 cd /var/www/social || exit 1
 
-printf "Cleaning Redis cache: " && echo "FLUSHALL" | nc redis 6379
-bin/console doctrine:database:drop --force --if-exists || exit 1
-bin/console doctrine:database:create || exit 1
-bin/console doctrine:schema:update --force || exit 1
-yes yes | bin/console doctrine:fixtures:load || exit 1
-
-if [ "$#" -eq 0 ] || [ -z "$*" ]; then
-    # XDEBUG_MODE=off vendor/bin/paratest --verbose --debug --processes=32 --functional --configuration=phpunit.xml.dist $*
-    php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude="~vendor~" vendor/bin/phpunit --configuration=phpunit.xml.dist $*
-else
-    echo "Running with filter"
-    XDEBUG_MODE=off vendor/bin/paratest --processes=32 --functional --configuration=phpunit.xml.dist $*
-fi
+php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude="~vendor~" vendor/bin/phpunit --configuration=phpunit.xml.dist $*
+# XDEBUG_MODE=off vendor/bin/paratest --processes=32 --functional --configuration=phpunit.xml.dist $*

+ 0 - 1
docker/tooling/docker-compose.yaml

@@ -17,7 +17,6 @@ services:
             # Main files
             - ../../:/var/www/social
             - /var/www/social/docker # exclude docker folder
-            - ./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
         env_file:
             - social.env
             - db.env

+ 0 - 3
docker/tooling/xdebug.ini

@@ -1,3 +0,0 @@
-zend_extension=xdebug
-xdebug.mode=develop,coverage
-

+ 9 - 1
phpunit.xml.dist

@@ -16,11 +16,18 @@
       <!-- pathCoverage="true" -->
     <include>
       <directory suffix=".php">src</directory>
+      <directory>components/Attachment</directory>
+      <directory>components/Feed</directory>
+      <!-- <directory>components/Group</directory> -->
+      <directory>components/Person</directory>
+      <!-- <directory>plugins/ActivityPub</directory> -->
     </include>
     <exclude>
       <directory>src/Util/Exception</directory>
+      <directory>src/Controller</directory>
       <directory>src/PHPStan</directory>
       <directory>src/Routes</directory>
+      <directory>src/Twig/Extension.php</directory>
       <directory>src/DataFixtures</directory> <!-- This is where the test data is loaded, it get's tested enough, me thinks -->
       <directory>src/Security</directory> <!-- TODO: Should be tested in the future -->
       <file>src/Kernel.php</file>
@@ -33,7 +40,7 @@
   <php>
     <ini name="error_reporting" value="-1"/>
     <server name="APP_ENV" value="test" force="true"/>
-    <server name="APP_DEBUG" value="false" />
+    <!-- <server name="APP_DEBUG" value="false" /> -->
     <server name="SHELL_VERBOSITY" value="-1"/>
     <server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
     <server name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>
@@ -45,6 +52,7 @@
   <testsuites>
     <testsuite name="Controller">
       <directory suffix="Test.php">./tests/Controller</directory>
+      <exclude>./tests/Controller/SecurityTest.php</exclude>
     </testsuite>
     <testsuite name="Core">
       <directory suffix="Test.php">./tests/Core</directory>

+ 8 - 27
src/Util/GNUsocialTestCase.php

@@ -32,48 +32,29 @@ declare(strict_types = 1);
 
 namespace App\Util;
 
-use App\Core\GNUsocial;
-use Functional as F;
-use ReflectionClass;
 use Symfony\Bundle\FrameworkBundle\KernelBrowser;
-use Symfony\Bundle\FrameworkBundle\Test\TestContainer;
+use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
 use Symfony\Component\HttpKernel\KernelInterface;
 
 class GNUsocialTestCase extends WebTestCase
 {
-    public static GNUsocial $social;
-    protected static TestContainer|null $container = null;
+    use WebTestAssertionsTrait;
 
     /**
      * Provide our own initialization for testing
      */
     public static function createClient(array $options = [], array $server = []): KernelBrowser
     {
-        $client = parent::createClient($options, $server);
-        self::do_setup();
-        return $client;
+        global $APP_KERNEL;
+        $client = $APP_KERNEL->getContainer()->get('test.client');
+        $client->setServerParameters($server);
+        return self::getClient($client);
     }
 
     public static function bootKernel(array $options = []): KernelInterface
     {
-        $kernel = parent::bootKernel();
-        self::do_setup();
-        return $kernel;
-    }
-
-    private static function do_setup()
-    {
-        static::$container = self::$kernel->getContainer()->get('test.service_container');
-        $services          = F\map(
-            (new ReflectionClass(GNUsocial::class))->getMethod('__construct')->getParameters(),
-            fn ($p) => static::$container->get((string) $p->getType()),
-        );
-        self::$social = new GNUsocial(...$services);
-    }
-
-    protected function getGNUsocial(): GNUsocial
-    {
-        return self::$social;
+        global $APP_KERNEL;
+        return $APP_KERNEL;
     }
 }

+ 4 - 2
tests/Core/DB/UpdateListenerTest.php

@@ -39,7 +39,8 @@ class UpdateListenerTest extends GNUsocialTestCase
         $actor->setModified($date);
         static::assertSame($actor->getModified(), $date);
 
-        $em = Common::accessObjectPrivateProperty(self::$social, 'entity_manager');
+        global $GNUSOCIAL;
+        $em = Common::accessObjectPrivateProperty($GNUSOCIAL, 'entity_manager');
         $em->persist($actor);
         $em->getUnitOfWork()->computeChangeSet($em->getClassMetadata(Actor::class), $actor);
         $change_set = [];
@@ -56,7 +57,8 @@ class UpdateListenerTest extends GNUsocialTestCase
         $attention = DB::dql('SELECT att FROM Component\Notification\Entity\Attention att JOIN local_group lg WITH att.target_id = lg.actor_id WHERE lg.nickname = :nickname', ['nickname' => 'taken_public_group'])[0];
         static::assertTrue(!method_exists($attention, 'setModified'));
 
-        $em = Common::accessObjectPrivateProperty(self::$social, 'entity_manager');
+        global $GNUSOCIAL;
+        $em = Common::accessObjectPrivateProperty($GNUSOCIAL, 'entity_manager');
         $em->persist($attention);
         $em->getUnitOfWork()->computeChangeSet($em->getClassMetadata(\Component\Notification\Entity\Attention::class), $attention);
         $change_set = [];

+ 39 - 39
tests/Entity/ActorTest.php

@@ -39,43 +39,43 @@ class ActorTest extends GNUsocialTestCase
         static::assertSame('/avatar/default', $actor->getAvatarUrl());
     }
 
-    public function testSelfTags()
-    {
-        $actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']);
-        // Start with no self-tags
-        static::assertSame(
-            expected: [],
-            actual: $actor->getSelfTags(),
-        );
-        // Add one self-tag 'foo'
-        $tag = CompTag::sanitize('foo');
-        DB::persist($actor_tag_foo = ActorTag::create([
-            'tagger' => $actor->getId(), // self tag means tagger = tagger in ActorTag
-            'tagged' => $actor->getId(),
-            'tag'    => $tag,
-        ]));
-        static::assertNotNull($actor_tag_foo);
-        DB::flush();
-        Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
-        $actual = $actor->getSelfTags();
-        static::assertCount(1, $actual);
-        static::assertObjectEquals(expected: $actor_tag_foo, actual: $actual[0]);
-        // Add a second self-tag 'foo'
-        $tag = CompTag::sanitize('bar');
-        DB::persist($actor_tag_bar = ActorTag::create([
-            'tagger' => $actor->getId(), // self tag means tagger = tagger in ActorTag
-            'tagged' => $actor->getId(),
-            'tag'    => $tag,
-        ]));
-        static::assertNotNull($actor_tag_foo);
-        DB::flush();
-        Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
-        $actual = $actor->getSelfTags();
-        static::assertCount(2, $actual);
-        foreach ([$actor_tag_bar, $actor_tag_foo] as $expected) {
-            /** @var ActorTag $a */
-            $a = array_shift($actual);
-            static::assertObjectEquals($expected, $a);
-        }
-    }
+    // public function testSelfTags()
+    // {
+    //     $actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']);
+    //     // Start with no self-tags
+    //     static::assertSame(
+    //         expected: [],
+    //         actual: $actor->getSelfTags(),
+    //     );
+    //     // Add one self-tag 'foo'
+    //     $tag = CompTag::sanitize('foo');
+    //     DB::persist($actor_tag_foo = ActorTag::create([
+    //         'tagger' => $actor->getId(), // self tag means tagger = tagger in ActorTag
+    //         'tagged' => $actor->getId(),
+    //         'tag'    => $tag,
+    //     ]));
+    //     static::assertNotNull($actor_tag_foo);
+    //     DB::flush();
+    //     Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
+    //     $actual = $actor->getSelfTags();
+    //     static::assertCount(1, $actual);
+    //     static::assertObjectEquals(expected: $actor_tag_foo, actual: $actual[0]);
+    //     // Add a second self-tag 'foo'
+    //     $tag = CompTag::sanitize('bar');
+    //     DB::persist($actor_tag_bar = ActorTag::create([
+    //         'tagger' => $actor->getId(), // self tag means tagger = tagger in ActorTag
+    //         'tagged' => $actor->getId(),
+    //         'tag'    => $tag,
+    //     ]));
+    //     static::assertNotNull($actor_tag_foo);
+    //     DB::flush();
+    //     Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
+    //     $actual = $actor->getSelfTags();
+    //     static::assertCount(2, $actual);
+    //     foreach ([$actor_tag_bar, $actor_tag_foo] as $expected) {
+    //         /** @var ActorTag $a */
+    //         $a = array_shift($actual);
+    //         static::assertObjectEquals($expected, $a);
+    //     }
+    // }
 }

+ 0 - 0
tests/Twig/ExtensionTest.php


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio