diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..b7886d1e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI +on: + push: ~ + pull_request: ~ + +jobs: + run: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: ['ubuntu-latest'] + php-versions: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + phpunit-versions: ['latest'] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl + ini-values: post_max_size=256M, max_execution_time=180 + tools: phpunit:${{ matrix.phpunit-versions }} + + - name: Install Dependencies + run: composer install --no-interaction --no-suggest --prefer-dist + + - name: Process the tests + run: vendor/bin/simple-phpunit diff --git a/.gitignore b/.gitignore index da76324f..8fc16d75 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ vendor .php_cs Tests/Functional/cache Tests/Functional/logs -var \ No newline at end of file +var +.phpunit.result.cache \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index e18482bb..c6736421 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ matrix: before_install: - echo "memory_limit=4G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - phpenv config-rm xdebug.ini + - composer self-update - if [ "$SYMFONY_LTS" != "" ]; then composer require --dev --no-update symfony/lts=$SYMFONY_LTS; fi install: @@ -30,3 +31,5 @@ install: - ./phpunit install script: ./phpunit + +dist: trusty diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 608c2436..bc39b192 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -10,6 +10,8 @@ */ class Configuration implements ConfigurationInterface { + const ROOT_NAME = 'fos_message'; + /** * Generates the configuration tree. * @@ -17,8 +19,12 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder('fos_message'); - $rootNode = $treeBuilder->root('fos_message'); + $treeBuilder = new TreeBuilder(self::ROOT_NAME); + if (\method_exists($treeBuilder, 'getRootNode')) { + $rootNode = $treeBuilder->getRootNode(); + } else { + $rootNode = $treeBuilder->root(self::ROOT_NAME); + } $rootNode ->children() diff --git a/Tests/Document/ThreadDenormalizerTest.php b/Tests/Document/ThreadDenormalizerTest.php index 55b21613..0196b206 100644 --- a/Tests/Document/ThreadDenormalizerTest.php +++ b/Tests/Document/ThreadDenormalizerTest.php @@ -12,7 +12,11 @@ class ThreadDenormalizerTest extends TestCase { protected $dates; - protected function setUp() + /** + * This method should be setUp(): void + * For compatibility reasons with old versions of PHP, we cannot use neither setUp(): void nor setUp(). + */ + protected function setUpBeforeTest() { $this->markTestIncomplete('Broken, needs to be fixed'); @@ -26,6 +30,8 @@ protected function setUp() public function testDenormalize() { + $this->setUpBeforeTest(); + $thread = new TestThread(); $user1 = $this->createParticipantMock('u1'); $user2 = $this->createParticipantMock('u2'); diff --git a/Tests/EntityManager/ThreadManagerTest.php b/Tests/EntityManager/ThreadManagerTest.php index bf815e47..2f20b3a2 100644 --- a/Tests/EntityManager/ThreadManagerTest.php +++ b/Tests/EntityManager/ThreadManagerTest.php @@ -16,7 +16,11 @@ class ThreadManagerTest extends TestCase protected $user; protected $date; - public function setUp() + /** + * This method should be setUp(): void + * For compatibility reasons with old versions of PHP, we cannot use neither setUp(): void nor setUp(). + */ + public function setUpBeforeTest() { $this->user = $this->createParticipantMock('4711'); $this->date = new \DateTime('2013-12-25'); @@ -27,6 +31,8 @@ public function setUp() */ public function testDoCreatedByAndAt() { + $this->setUpBeforeTest(); + $thread = $this->createThreadMock(); $thread->expects($this->exactly(1))->method('getFirstMessage') ->will($this->returnValue($this->createMessageMock())); @@ -40,6 +46,8 @@ public function testDoCreatedByAndAt() */ public function testDoCreatedByAndAtWithCreatedBy() { + $this->setUpBeforeTest(); + $thread = $this->createThreadMock(); $thread->expects($this->exactly(0))->method('setCreatedBy'); @@ -59,6 +67,8 @@ public function testDoCreatedByAndAtWithCreatedBy() */ public function testDoCreatedByAndAtWithCreatedAt() { + $this->setUpBeforeTest(); + $thread = $this->createThreadMock(); $thread->expects($this->exactly(1))->method('setCreatedBy'); @@ -78,6 +88,8 @@ public function testDoCreatedByAndAtWithCreatedAt() */ public function testDoCreatedByAndAtWithCreatedAtAndBy() { + $this->setUpBeforeTest(); + $thread = $this->createThreadMock(); $thread->expects($this->exactly(0))->method('setCreatedBy'); $thread->expects($this->exactly(0))->method('setCreatedAt'); @@ -99,6 +111,8 @@ public function testDoCreatedByAndAtWithCreatedAtAndBy() */ public function testDoCreatedByAndNoMessage() { + $this->setUpBeforeTest(); + $thread = $this->createThreadMock(); $thread->expects($this->exactly(0))->method('setCreatedBy'); $thread->expects($this->exactly(0))->method('setCreatedAt'); diff --git a/Tests/Twig/Extension/MessageExtensionTest.php b/Tests/Twig/Extension/MessageExtensionTest.php index 7e17e665..85597bc8 100644 --- a/Tests/Twig/Extension/MessageExtensionTest.php +++ b/Tests/Twig/Extension/MessageExtensionTest.php @@ -16,7 +16,11 @@ class MessageExtensionTest extends TestCase private $authorizer; private $participant; - public function setUp() + /** + * This method should be setUp(): void + * For compatibility reasons with old versions of PHP, we cannot use neither setUp(): void nor setUp(). + */ + public function setUpBeforeTest() { $this->participantProvider = $this->getMockBuilder('FOS\MessageBundle\Security\ParticipantProviderInterface')->getMock(); $this->provider = $this->getMockBuilder('FOS\MessageBundle\Provider\ProviderInterface')->getMock(); @@ -27,6 +31,8 @@ public function setUp() public function testIsReadReturnsTrueWhenRead() { + $this->setUpBeforeTest(); + $this->participantProvider->expects($this->once())->method('getAuthenticatedParticipant')->will($this->returnValue($this->participant)); $readAble = $this->getMockBuilder('FOS\MessageBundle\Model\ReadableInterface')->getMock(); $readAble->expects($this->once())->method('isReadByParticipant')->with($this->participant)->will($this->returnValue(true)); @@ -35,6 +41,8 @@ public function testIsReadReturnsTrueWhenRead() public function testIsReadReturnsFalseWhenNotRead() { + $this->setUpBeforeTest(); + $this->participantProvider->expects($this->once())->method('getAuthenticatedParticipant')->will($this->returnValue($this->participant)); $readAble = $this->getMockBuilder('FOS\MessageBundle\Model\ReadableInterface')->getMock(); $readAble->expects($this->once())->method('isReadByParticipant')->with($this->participant)->will($this->returnValue(false)); @@ -43,6 +51,8 @@ public function testIsReadReturnsFalseWhenNotRead() public function testCanDeleteThreadWhenHasPermission() { + $this->setUpBeforeTest(); + $thread = $this->getThreadMock(); $this->authorizer->expects($this->once())->method('canDeleteThread')->with($thread)->will($this->returnValue(true)); $this->assertTrue($this->extension->canDeleteThread($thread)); @@ -50,6 +60,8 @@ public function testCanDeleteThreadWhenHasPermission() public function testCanDeleteThreadWhenNoPermission() { + $this->setUpBeforeTest(); + $thread = $this->getThreadMock(); $this->authorizer->expects($this->once())->method('canDeleteThread')->with($thread)->will($this->returnValue(false)); $this->assertFalse($this->extension->canDeleteThread($thread)); @@ -57,6 +69,8 @@ public function testCanDeleteThreadWhenNoPermission() public function testIsThreadDeletedByParticipantWhenDeleted() { + $this->setUpBeforeTest(); + $thread = $this->getThreadMock(); $this->participantProvider->expects($this->once())->method('getAuthenticatedParticipant')->will($this->returnValue($this->participant)); $thread->expects($this->once())->method('isDeletedByParticipant')->with($this->participant)->will($this->returnValue(true)); @@ -65,19 +79,37 @@ public function testIsThreadDeletedByParticipantWhenDeleted() public function testGetNbUnreadCacheStartsEmpty() { - $this->assertAttributeEmpty('nbUnreadMessagesCache', $this->extension); + $this->setUpBeforeTest(); + + /* + * assertAttributeEmpty is deprecated, see deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 + */ +// if (\method_exists($this, 'assertAttributeEmpty')) { +// $this->assertAttributeEmpty('nbUnreadMessagesCache', $this->extension); +// } + $this->assertEmpty($this->extension->getNbUnread()); $this->extension->getNbUnread(); } public function testGetNbUnread() { - $this->assertAttributeEmpty('nbUnreadMessagesCache', $this->extension); + $this->setUpBeforeTest(); + + /* + * assertAttributeEmpty is deprecated, see deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 + */ +// if (\method_exists($this, 'assertAttributeEmpty')) { +// $this->assertAttributeEmpty('nbUnreadMessagesCache', $this->extension); +// } + $this->assertEmpty($this->extension->getNbUnread()); $this->provider->expects($this->once())->method('getNbUnreadMessages')->will($this->returnValue(3)); $this->assertEquals(3, $this->extension->getNbUnread()); } public function testGetNbUnreadStoresCache() { + $this->setUpBeforeTest(); + $this->provider->expects($this->once())->method('getNbUnreadMessages')->will($this->returnValue(3)); //we call it twice but expect to only get one call $this->extension->getNbUnread(); @@ -86,6 +118,8 @@ public function testGetNbUnreadStoresCache() public function testGetName() { + $this->setUpBeforeTest(); + $this->assertEquals('fos_message', $this->extension->getName()); } diff --git a/Twig/Extension/MessageExtension.php b/Twig/Extension/MessageExtension.php index 64d10932..dba25a4c 100644 --- a/Twig/Extension/MessageExtension.php +++ b/Twig/Extension/MessageExtension.php @@ -8,8 +8,10 @@ use FOS\MessageBundle\Provider\ProviderInterface; use FOS\MessageBundle\Security\AuthorizerInterface; use FOS\MessageBundle\Security\ParticipantProviderInterface; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; -class MessageExtension extends \Twig_Extension +class MessageExtension extends AbstractExtension { protected $participantProvider; protected $provider; @@ -30,10 +32,10 @@ public function __construct(ParticipantProviderInterface $participantProvider, P public function getFunctions() { return array( - new \Twig_SimpleFunction('fos_message_is_read', array($this, 'isRead')), - new \Twig_SimpleFunction('fos_message_nb_unread', array($this, 'getNbUnread')), - new \Twig_SimpleFunction('fos_message_can_delete_thread', array($this, 'canDeleteThread')), - new \Twig_SimpleFunction('fos_message_deleted_by_participant', array($this, 'isThreadDeletedByParticipant')), + new TwigFunction('fos_message_is_read', array($this, 'isRead')), + new TwigFunction('fos_message_nb_unread', array($this, 'getNbUnread')), + new TwigFunction('fos_message_can_delete_thread', array($this, 'canDeleteThread')), + new TwigFunction('fos_message_deleted_by_participant', array($this, 'isThreadDeletedByParticipant')), ); } diff --git a/composer.json b/composer.json index ff33a8d2..493bd5f7 100644 --- a/composer.json +++ b/composer.json @@ -47,5 +47,12 @@ "branch-alias": { "dev-master": "2.0-dev" } - } + }, + "repositories": [ + { + "type": "composer", + "url": "https://packagist.org" + }, + { "packagist": false } + ] } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e182b4ab..408377e9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,7 @@ +