Skip to content

Commit

Permalink
Merge pull request #360 from encreinformatique/lts-support
Browse files Browse the repository at this point in the history
LTS support, Travis and PHPunit issues revised and Github Actions
  • Loading branch information
GuilhemN authored Dec 20, 2022
2 parents 9afcc54 + 4b0db92 commit 03eef7e
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 14 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ vendor
.php_cs
Tests/Functional/cache
Tests/Functional/logs
var
var
.phpunit.result.cache
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ 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:
- composer update $COMPOSER_FLAGS
- ./phpunit install

script: ./phpunit

dist: trusty
10 changes: 8 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
*/
class Configuration implements ConfigurationInterface
{
const ROOT_NAME = 'fos_message';

/**
* Generates the configuration tree.
*
* @return TreeBuilder
*/
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()
Expand Down
8 changes: 7 additions & 1 deletion Tests/Document/ThreadDenormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -26,6 +30,8 @@ protected function setUp()

public function testDenormalize()
{
$this->setUpBeforeTest();

$thread = new TestThread();
$user1 = $this->createParticipantMock('u1');
$user2 = $this->createParticipantMock('u2');
Expand Down
16 changes: 15 additions & 1 deletion Tests/EntityManager/ThreadManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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()));
Expand All @@ -40,6 +46,8 @@ public function testDoCreatedByAndAt()
*/
public function testDoCreatedByAndAtWithCreatedBy()
{
$this->setUpBeforeTest();

$thread = $this->createThreadMock();

$thread->expects($this->exactly(0))->method('setCreatedBy');
Expand All @@ -59,6 +67,8 @@ public function testDoCreatedByAndAtWithCreatedBy()
*/
public function testDoCreatedByAndAtWithCreatedAt()
{
$this->setUpBeforeTest();

$thread = $this->createThreadMock();

$thread->expects($this->exactly(1))->method('setCreatedBy');
Expand All @@ -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');
Expand All @@ -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');
Expand Down
40 changes: 37 additions & 3 deletions Tests/Twig/Extension/MessageExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -43,20 +51,26 @@ 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));
}

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));
}

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));
Expand All @@ -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();
Expand All @@ -86,6 +118,8 @@ public function testGetNbUnreadStoresCache()

public function testGetName()
{
$this->setUpBeforeTest();

$this->assertEquals('fos_message', $this->extension->getName());
}

Expand Down
12 changes: 7 additions & 5 deletions Twig/Extension/MessageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')),
);
}

Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,12 @@
"branch-alias": {
"dev-master": "2.0-dev"
}
}
},
"repositories": [
{
"type": "composer",
"url": "https://packagist.org"
},
{ "packagist": false }
]
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<phpunit bootstrap="./vendor/autoload.php" color="true">
<php>
<ini name="xdebug.max_nesting_level" value="200" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>
<testsuites>
<testsuite name="FOSMessageBundle">
Expand Down

0 comments on commit 03eef7e

Please sign in to comment.