From 4a85726e5583e7de497077ded4e2ffbcd8b8a0b9 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sun, 5 Feb 2017 01:38:12 +0100 Subject: :construction_worker: :arrow_up: :heavy_plus_sign: Update PHPUnit to current stable 6. Update requirements to PHP7 for dev. Add php-mock-phpunit to mock and stub global functions in a better way. --- tests/phpunit-mysql.xml | 12 +-- tests/phpunit-pgsql.xml | 12 +-- tests/unit/Lib/PermissionDescriptionTest.php | 129 ++++++++++++--------------- 3 files changed, 69 insertions(+), 84 deletions(-) (limited to 'tests') diff --git a/tests/phpunit-mysql.xml b/tests/phpunit-mysql.xml index 9ba40f087..171211094 100644 --- a/tests/phpunit-mysql.xml +++ b/tests/phpunit-mysql.xml @@ -1,12 +1,11 @@ ./unit/ @@ -31,7 +30,8 @@ - + + diff --git a/tests/phpunit-pgsql.xml b/tests/phpunit-pgsql.xml index f59dd05ad..ace14e196 100644 --- a/tests/phpunit-pgsql.xml +++ b/tests/phpunit-pgsql.xml @@ -1,12 +1,11 @@ ./unit/ @@ -28,7 +27,8 @@ - + + diff --git a/tests/unit/Lib/PermissionDescriptionTest.php b/tests/unit/Lib/PermissionDescriptionTest.php index b1da5a0fd..97a39a2c8 100644 --- a/tests/unit/Lib/PermissionDescriptionTest.php +++ b/tests/unit/Lib/PermissionDescriptionTest.php @@ -1,6 +1,6 @@ assertEquals($permDesc, $permDesc2); + $this->assertNotEquals($permDesc, $permDesc3); + } - public function testFromDescription() { - $permDesc = PermissionDescription::fromDescription('test'); - $permDesc2 = PermissionDescription::fromDescription('test'); - $permDesc3 = PermissionDescription::fromDescription('test2'); + public function testFromStandalonePermission() { + // Create a stub for global function t() + $t = $this->getFunctionMock('Zotlabs\Lib', 't'); + $t->expects($this->atLeastOnce())->willReturnCallback( + function ($string) { + return $string; + } + ); + // Create a mock for global function logger() + $this->getFunctionMock('Zotlabs\Lib', 'logger'); - $this->assertEquals($permDesc, $permDesc2); - $this->assertNotEquals($permDesc, $permDesc3); - } + $permDescUnknown = PermissionDescription::fromStandalonePermission(-1); + $permDescSelf = PermissionDescription::fromStandalonePermission(0); - public function testFromStandalonePermission() { - $permDescUnknown = PermissionDescription::fromStandalonePermission(-1); - $permDescSelf = PermissionDescription::fromStandalonePermission(0); + $this->assertNull($permDescUnknown); + $this->assertNotNull($permDescSelf); + } - $this->assertNull($permDescUnknown); - $this->assertNotNull($permDescSelf); - } + public function testFromGlobalPermission() { + //$permDesc = PermissionDescription::fromGlobalPermission('view_profile'); - public function testFromGlobalPermission() { - //$permDesc = PermissionDescription::fromGlobalPermission('view_profile'); + $this->markTestIncomplete( + 'The method fromGlobalPermission() is not yet testable ...' + ); + } - $this->markTestIncomplete( - 'For this test we need more stubs...' - ); - } + public function testGetPermissionDescription() { + // Create a stub for global function t() + $t = $this->getFunctionMock('Zotlabs\Lib', 't'); + $t->expects($this->atLeastOnce())->willReturnCallback( + function ($string) { + return $string; + } + ); + // Create a mock for global function logger() + $this->getFunctionMock('Zotlabs\Lib', 'logger'); - public function testGetPermissionDescription() { + // Create a stub for the PermissionDescription class + $stub = $this->createMock(PermissionDescription::class); + $stub->method('get_permission_description') + ->will($this->returnArgument(0)); - // fromStandalonePermission uses get_permission_description(), so that will not help - //$permDescSelf = PermissionDescription::fromStandalonePermission(0); - //$permDescPublic = PermissionDescription::fromStandalonePermission(PERMS_PUBLIC); + $permDescSelf = PermissionDescription::fromStandalonePermission(0); + $this->assertInstanceOf(PermissionDescription::class, $permDescSelf); + $this->assertEquals($permDescSelf->get_permission_description(), 'Only me'); - $this->markTestIncomplete( - 'For this test we need a mock of PermissionDescription...' - ); - //$permDescSelf = - //$this->assertEquals($permDescSelf->, 'Only me'); - //$this->assertEquals($permDescPublic, 'Public'); - } + $permDescPublic = PermissionDescription::fromStandalonePermission(PERMS_PUBLIC); + $this->assertEquals($permDescPublic->get_permission_description(), 'Public'); } } -- cgit v1.2.3