]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Enable PHPStan 3859/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Thu, 17 Jan 2019 13:28:05 +0000 (14:28 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 18 Jan 2019 14:25:50 +0000 (15:25 +0100)
- Fix error for level 0 & 1 (level 7 has 699 errors...)
- Add `updated_at` to site_credential (so the `timestamps()` method applies correctly)

27 files changed:
.travis.yml
app/DoctrineMigrations/Version20190117131816.php [new file with mode: 0644]
composer.json
phpstan.neon [new file with mode: 0644]
src/Wallabag/CoreBundle/Command/InstallCommand.php
src/Wallabag/CoreBundle/Entity/SiteCredential.php
src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
tests/Wallabag/CoreBundle/Helper/RedirectTest.php
tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php
tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php [new file with mode: 0644]

index 9d7fd3a0da32b36504f0187a0c888efef48c8018..ac64839d0c9dca6bdbf9bfc2411dc0fd700a648e 100644 (file)
@@ -67,6 +67,8 @@ script:
     - make fixtures
 
     - if [[ $VALIDATE_TRANSLATION_FILE = '' ]]; then SYMFONY_PHPUNIT_VERSION=6.5 ./bin/simple-phpunit -v ; fi;
+    # PHPStan needs PHPUnit to be installed and cache app to be generated
+    - if [[ $VALIDATE_TRANSLATION_FILE = '' ]]; then php bin/phpstan analyse src tests --no-progress --level 1 ; fi;
     - if [[ $CS_FIXER = run ]]; then php bin/php-cs-fixer fix --verbose --dry-run ; fi;
     - if [[ $VALIDATE_TRANSLATION_FILE = run ]]; then php bin/console lint:yaml src/Wallabag/CoreBundle/Resources/translations -v ; fi;
     - if [[ $VALIDATE_TRANSLATION_FILE = run ]]; then php bin/console lint:yaml app/Resources/CraueConfigBundle/translations -v ; fi;
diff --git a/app/DoctrineMigrations/Version20190117131816.php b/app/DoctrineMigrations/Version20190117131816.php
new file mode 100644 (file)
index 0000000..6548b9f
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Schema\Schema;
+use Wallabag\CoreBundle\Doctrine\WallabagMigration;
+
+/**
+ * Add updated_at fields to site_credential table.
+ */
+final class Version20190117131816 extends WallabagMigration
+{
+    public function up(Schema $schema): void
+    {
+        $siteCredentialTable = $schema->getTable($this->getTable('site_credential'));
+
+        $this->skipIf($siteCredentialTable->hasColumn('updated_at'), 'It seems that you already played this migration.');
+
+        $siteCredentialTable->addColumn('updated_at', 'datetime', [
+            'notnull' => false,
+        ]);
+    }
+
+    public function down(Schema $schema): void
+    {
+        $siteCredentialTable = $schema->getTable($this->getTable('site_credential'));
+
+        $this->skipIf(!$siteCredentialTable->hasColumn('updated_at'), 'It seems that you already played this migration.');
+
+        $siteCredentialTable->dropColumn('updated_at');
+    }
+}
index 8b28f06510d6467811221295a3a7325747a29fdc..89286c7f7566a6ac42509abcc160c845daa48d80 100644 (file)
         "symfony/phpunit-bridge": "^4.2",
         "friendsofphp/php-cs-fixer": "~2.13",
         "m6web/redis-mock": "^4.1",
-        "dama/doctrine-test-bundle": "^5.0"
+        "dama/doctrine-test-bundle": "^5.0",
+        "phpstan/phpstan": "^0.11.0",
+        "phpstan/phpstan-phpunit": "^0.11.0",
+        "phpstan/phpstan-symfony": "^0.11.0",
+        "phpstan/phpstan-doctrine": "^0.11.0"
     },
     "scripts": {
         "post-cmd": [
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644 (file)
index 0000000..dfbc97a
--- /dev/null
@@ -0,0 +1,13 @@
+includes:
+    - vendor/phpstan/phpstan-phpunit/extension.neon
+    - vendor/phpstan/phpstan-symfony/extension.neon
+    - vendor/phpstan/phpstan-doctrine/extension.neon
+    - vendor/phpstan/phpstan-phpunit/rules.neon
+
+parameters:
+    symfony:
+        container_xml_path: %rootDir%/../../../var/cache/test/appTestDebugProjectContainer.xml
+
+    # https://github.com/phpstan/phpstan/issues/694#issuecomment-350724288
+    autoload_files:
+        - vendor/bin/.phpunit/phpunit-6.5/vendor/autoload.php
index 3c76545cd37c8411e6223ade425fe93ff965ae6e..49c84178fa109d353d318647a9a7283e04cb3c09 100644 (file)
@@ -94,8 +94,9 @@ class InstallCommand extends ContainerAwareCommand
         $status = '<info>OK!</info>';
         $help = '';
 
+        $conn = $this->getContainer()->get('doctrine')->getManager()->getConnection();
+
         try {
-            $conn = $this->getContainer()->get('doctrine')->getManager()->getConnection();
             $conn->connect();
         } catch (\Exception $e) {
             if (false === strpos($e->getMessage(), 'Unknown database')
index ac714359d6b817b5fc7a901ae84dc1e85cac52e6..dee48fd52982efd20f709f1cbce92edfe12f4de8 100644 (file)
@@ -59,6 +59,13 @@ class SiteCredential
      */
     private $createdAt;
 
+    /**
+     * @var \DateTime
+     *
+     * @ORM\Column(name="updated_at", type="datetime")
+     */
+    private $updatedAt;
+
     /**
      * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="siteCredentials")
      */
@@ -178,6 +185,16 @@ class SiteCredential
         return $this->createdAt;
     }
 
+    /**
+     * Get updatedAt.
+     *
+     * @return \DateTime
+     */
+    public function getUpdatedAt()
+    {
+        return $this->updatedAt;
+    }
+
     /**
      * @return User
      */
index 63f65067da31381b6f0622863f337a46fc78852e..fbdf2ac7a706bdcb0d862f8fb719ab279b5a72fb 100644 (file)
@@ -6,6 +6,7 @@ use Psr\Log\LoggerInterface;
 use RulerZ\RulerZ;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
+use Wallabag\CoreBundle\Entity\TaggingRule;
 use Wallabag\CoreBundle\Repository\EntryRepository;
 use Wallabag\CoreBundle\Repository\TagRepository;
 use Wallabag\UserBundle\Entity\User;
index 537283f2539a8127a35a478d9a80f738f5180a62..2c46e0a1deff5f7c1b870af3a76a792674d684c8 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\AnnotationBundle\Controller;
+namespace Tests\Wallabag\AnnotationBundle\Controller;
 
 use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase;
 use Wallabag\AnnotationBundle\Entity\Annotation;
index 1a41338c3dfd241f039a25f20784f04b94239cdd..0b0c0276955c2bcd410a9039a624e48f36611d29 100644 (file)
@@ -794,7 +794,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
         $content = json_decode($this->client->getResponse()->getContent(), true);
 
         $this->assertArrayHasKey('tags', $content);
-        $this->assertSame($nbTags + 3, \count($content['tags']));
+        $this->assertCount($nbTags + 3, $content['tags']);
 
         $entryDB = $this->client->getContainer()
             ->get('doctrine.orm.entity_manager')
@@ -834,7 +834,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
         $content = json_decode($this->client->getResponse()->getContent(), true);
 
         $this->assertArrayHasKey('tags', $content);
-        $this->assertSame($nbTags - 1, \count($content['tags']));
+        $this->assertCount($nbTags - 1, $content['tags']);
     }
 
     public function testSaveIsArchivedAfterPost()
index cf9f1e97dc2e64203a0e2335a3e0c5fe70c4a451..c9dbbaa3b5afd0ab4a117821ae8105f4d8a59b79 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace tests\Wallabag\CoreBundle\Controller;
+namespace Tests\Wallabag\CoreBundle\Controller;
 
 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 use Wallabag\AnnotationBundle\Entity\Annotation;
index 006ca330564a7413ed3eafa283f0f71533cc221e..005296ff33572c742db613f845289a37f7d43f19 100644 (file)
@@ -522,9 +522,12 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->followRedirect();
 
-        $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
+        $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
+        $this->assertGreaterThan(1, $title);
         $this->assertContains('My updated title hehe :)', $title[0]);
-        $this->assertSame(1, \count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
+
+        $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
+        $this->assertCount(1, $stats);
         $this->assertNotContains('example.io', trim($stats[0]));
     }
 
@@ -1327,10 +1330,6 @@ class EntryControllerTest extends WallabagCoreTestCase
                 'http://www.hao123.com/shequ?__noscript__-=1',
                 'zh_CN',
             ],
-            'ru' => [
-                'https://www.kp.ru/daily/26879.7/3921982/',
-                'ru',
-            ],
             'pt_BR' => [
                 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
                 'pt_BR',
index 0c3d4c83adc721c2b0ac9a84d82f9d7cc9d19db4..d7ce7c45a9890fc2fce96178e45a0e703ac3701b 100644 (file)
@@ -180,7 +180,7 @@ class ExportControllerTest extends WallabagCoreTestCase
 
         $this->assertGreaterThan(1, $csv);
         // +1 for title line
-        $this->assertSame(\count($contentInDB) + 1, \count($csv));
+        $this->assertCount(\count($contentInDB) + 1, $csv);
         $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]);
         $this->assertContains($contentInDB[0]['title'], $csv[1]);
         $this->assertContains($contentInDB[0]['url'], $csv[1]);
index 2af6e14f3d80b1a352db946ab0a4ce2554ce9d31..afa906210f0edf2945f5772b33c2316be13b7435 100644 (file)
@@ -11,7 +11,7 @@ class RssControllerTest extends WallabagCoreTestCase
         $doc = new \DOMDocument();
         $doc->loadXML($xml);
 
-        $xpath = new \DOMXpath($doc);
+        $xpath = new \DOMXPath($doc);
 
         if (null === $nb) {
             $this->assertGreaterThan(0, $xpath->query('//item')->length);
index 04e1a59c83fe1ca4371013e400db4aa1b5c71755..29e12cbe5c90832716edea6550fbf09bb171c543 100644 (file)
@@ -17,6 +17,9 @@ class RedirectTest extends TestCase
     /** @var Redirect */
     private $redirect;
 
+    /** @var UsernamePasswordToken */
+    private $token;
+
     public function setUp()
     {
         $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router')
index b044a700ef3dd672732a25fa8a4e0013401633a1..800af5c9da835fda31b413be85bf3b0fa301d185 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Wallabag\CoreBundle\Command;
+namespace Tests\Wallabag\CoreBundle\ParamConverter;
 
 use PHPUnit\Framework\TestCase;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
index b2141c04095834a3e38e57d19176e8dc973bc572..b7f6192d354c28bfbc962ed05f89b8571f1ec578 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Wallabag\ImportBundle\Consumer\AMQP;
+namespace Tests\Wallabag\ImportBundle\Consumer;
 
 use PhpAmqpLib\Message\AMQPMessage;
 use PHPUnit\Framework\TestCase;
index 61337e47e6c9024813c575f48d5eccd78c7578c8..e1bd88272e12751735e538029412e3c0324e3963 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Wallabag\ImportBundle\Consumer\AMQP;
+namespace Tests\Wallabag\ImportBundle\Consumer;
 
 use PHPUnit\Framework\TestCase;
 use Wallabag\CoreBundle\Entity\Entry;
index cd3e41e98e7d83b8d88c9687d2f91028cd7fbb67..d3ffbb6d0378cbf9e1a40851792f44f4b08a7d7f 100644 (file)
@@ -121,7 +121,7 @@ class ChromeControllerTest extends WallabagCoreTestCase
         $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok');
-        $this->assertSame(1, \count($content->getTags()));
+        $this->assertCount(1, $content->getTags());
 
         $createdAt = $content->getCreatedAt();
         $this->assertSame('2011', $createdAt->format('Y'));
index dc5ed6d0c851198f8f3baacb7cadd5246e8d9096..3e64f2e5689a2369111ffec7db4a7c7fed1d9a9b 100644 (file)
@@ -122,7 +122,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase
         $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok');
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok');
-        $this->assertSame(3, \count($content->getTags()));
+        $this->assertCount(3, $content->getTags());
 
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
index 7390fa8849a33965e67cc0be886e4f50ce269f3f..05347767d967063e82b855249b384ccf133bcb11 100644 (file)
@@ -124,7 +124,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.liberation.fr is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.liberation.fr is ok');
         $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag');
-        $this->assertSame(1, \count($content->getTags()));
+        $this->assertCount(1, $content->getTags());
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
 
         $content = $client->getContainer()
@@ -138,7 +138,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase
         $this->assertContains('foot', $content->getTags());
         $this->assertContains('test_tag', $content->getTags());
 
-        $this->assertSame(2, \count($content->getTags()));
+        $this->assertCount(2, $content->getTags());
     }
 
     public function testImportInstapaperWithFileAndMarkAllAsRead()
index 80819f45757f4699dcdd09b6f24e8dab843ae266..15646d55bad84fab1bf79f1107150426bae2fce9 100644 (file)
@@ -127,7 +127,7 @@ class PinboardControllerTest extends WallabagCoreTestCase
         $this->assertContains('foot', $tags, 'It includes the "foot" tag');
         $this->assertContains('varnish', $tags, 'It includes the "varnish" tag');
         $this->assertContains('php', $tags, 'It includes the "php" tag');
-        $this->assertSame(3, \count($tags));
+        $this->assertCount(3, $tags);
 
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
         $this->assertSame('2016-10-26', $content->getCreatedAt()->format('Y-m-d'));
index 5619659adab49f43462fc748b4295b440d0f0ce0..4f2f40536487a4c5049ddcc195b0f0259af79b4b 100644 (file)
@@ -125,7 +125,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
 
         $tags = $content->getTags();
         $this->assertContains('foot', $tags, 'It includes the "foot" tag');
-        $this->assertSame(1, \count($tags));
+        $this->assertCount(1, $tags);
 
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
         $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
index c67941a71046813cabd5b3d227b42a79d43eb24b..1f57939d997d9883a10c0693a108906a0bab1fd4 100644 (file)
@@ -127,7 +127,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
         $tags = $content->getTags();
         $this->assertContains('foot', $tags, 'It includes the "foot" tag');
         $this->assertContains('framabag', $tags, 'It includes the "framabag" tag');
-        $this->assertSame(2, \count($tags));
+        $this->assertCount(2, $tags);
 
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
     }
index 822656ba4ba0789d05c9f93924fefbcddaa83e02..b606e26ae627fe4b0ceddc406e46f147bf08ce31 100644 (file)
@@ -128,7 +128,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
 
         $tags = $content->getTags();
         $this->assertContains('foot', $tags, 'It includes the "foot" tag');
-        $this->assertSame(1, \count($tags));
+        $this->assertCount(1, $tags);
 
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
@@ -147,7 +147,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
         $this->assertContains('foot', $tags, 'It includes the "foot" tag');
         $this->assertContains('mediapart', $tags, 'It includes the "mediapart" tag');
         $this->assertContains('blog', $tags, 'It includes the "blog" tag');
-        $this->assertSame(3, \count($tags));
+        $this->assertCount(3, $tags);
 
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
         $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
index adc2cf09355c08948ea1dd260192fd0d9c368f9a..f44e6fbf60028b9e7b9ebb5f918abc8810f2a0fb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wallabag\UserBundle\Tests\Controller;
+namespace Tests\Wallabag\UserBundle\Controller;
 
 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 
index aa1760688232603c85b775a851311b1c2104cb4d..e34e13a8a29cf2a7bab12a7a163f57ea226114c8 100644 (file)
@@ -6,22 +6,6 @@ use PHPUnit\Framework\TestCase;
 use Wallabag\UserBundle\Entity\User;
 use Wallabag\UserBundle\Mailer\AuthCodeMailer;
 
-/**
- * @see https://www.pmg.com/blog/integration-testing-swift-mailer/
- */
-final class CountableMemorySpool extends \Swift_MemorySpool implements \Countable
-{
-    public function count()
-    {
-        return \count($this->messages);
-    }
-
-    public function getMessages()
-    {
-        return $this->messages;
-    }
-}
-
 class AuthCodeMailerTest extends TestCase
 {
     protected $mailer;
diff --git a/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php b/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php
new file mode 100644 (file)
index 0000000..53f240a
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+namespace Tests\Wallabag\UserBundle\Mailer;
+
+/**
+ * @see https://www.pmg.com/blog/integration-testing-swift-mailer/
+ */
+final class CountableMemorySpool extends \Swift_MemorySpool implements \Countable
+{
+    public function count()
+    {
+        return \count($this->messages);
+    }
+
+    public function getMessages()
+    {
+        return $this->messages;
+    }
+}