diff --git a/.gitignore b/.gitignore index 67854e2..8f48067 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ vendor/ build/ composer.lock +.phpunit.result.cache +.idea diff --git a/composer.json b/composer.json index 659ba64..38194f7 100644 --- a/composer.json +++ b/composer.json @@ -12,14 +12,14 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=8.0.0", "ext-json":"*", "regex-guard/regex-guard": "~1.0", - "nikic/php-parser" : ">=2.0 <5.0.0" + "nikic/php-parser" : "^5.0" }, "require-dev": { - "mockery/mockery": "^0.9", - "phpunit/phpunit": ">=4.8 <6.0.0" + "mockery/mockery": "^1.6", + "phpunit/phpunit": ">=8.5.0" }, "autoload": { "psr-4": { "Minime\\Annotations\\": "src/" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a1772a1..ca82e19 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,50 +2,47 @@ + stopOnFailure="false" + failOnWarning="true" +> - + test/suite/ - - - src/ - - + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AnnotationsBag.php b/src/AnnotationsBag.php index b27043d..607a917 100644 --- a/src/AnnotationsBag.php +++ b/src/AnnotationsBag.php @@ -2,6 +2,7 @@ namespace Minime\Annotations; +use Traversable; use Minime\Annotations\Interfaces\AnnotationsBagInterface; use RegexGuard\Factory as RegexGuard; use ArrayIterator; @@ -153,7 +154,7 @@ public function union(AnnotationsBagInterface $bag) /** * Countable */ - public function count() + public function count() : int { return count($this->attributes); } @@ -161,7 +162,7 @@ public function count() /** * JsonSerializable */ - public function jsonSerialize() + public function jsonSerialize(): mixed { return $this->toArray(); } @@ -169,7 +170,7 @@ public function jsonSerialize() /** * IteratorAggregate */ - public function getIterator() + public function getIterator() : Traversable { return new ArrayIterator($this->attributes); } @@ -177,7 +178,7 @@ public function getIterator() /** * ArrayAccess - Whether or not an offset exists. */ - public function offsetExists($key) + public function offsetExists($key): bool { return $this->has($key); } @@ -185,7 +186,7 @@ public function offsetExists($key) /** * ArrayAccess - Returns the value at specified offset. */ - public function offsetGet($key) + public function offsetGet($key) : mixed { return $this->get($key); } @@ -193,17 +194,15 @@ public function offsetGet($key) /** * ArrayAccess - Assigns a value to the specified offset. */ - public function offsetSet($key, $value) + public function offsetSet($key, $value): void { $this->set($key, $value); - - return true; } /** * ArrayAccess - Unsets an offset. */ - public function offsetUnset($key) + public function offsetUnset($key) : void { unset($this->attributes[$key]); } diff --git a/src/Cache/ApcCache.php b/src/Cache/ApcCache.php index 5c76b0b..6669ea9 100644 --- a/src/Cache/ApcCache.php +++ b/src/Cache/ApcCache.php @@ -26,15 +26,15 @@ public function getKey($docblock) public function set($key, array $annotations) { - if (! apc_exists($key)) { - apc_store($key, $annotations); + if (! apcu_exists($key)) { + apcu_store($key, $annotations); } } public function get($key) { - if (apc_exists($key)) { - return apc_fetch($key); + if (apcu_exists($key)) { + return apcu_fetch($key); } return []; @@ -42,11 +42,13 @@ public function get($key) public function clear() { - $cache = apc_cache_info('user'); - foreach ($cache['cache_list'] as $entry) { - if(isset($entry['info']) - && strpos($entry['info'], 'minime-annotations:') === 0) { - apc_delete($entry['info']); + $cache = apcu_cache_info(); + if ($cache) { + foreach ($cache['cache_list'] as $entry) { + if(isset($entry['info']) + && strpos($entry['info'], 'minime-annotations:') === 0) { + apcu_delete($entry['info']); + } } } } diff --git a/src/DynamicParser.php b/src/DynamicParser.php index 4e3c967..f78ce65 100644 --- a/src/DynamicParser.php +++ b/src/DynamicParser.php @@ -77,7 +77,7 @@ protected function getDocblockTagsSection($docblock) * @param string $docblock A raw docblok string * @return string A docblok string without delimiters */ - protected function sanitizeDocblock($docblock) + protected function sanitizeDocblock(string $docblock) { return preg_replace('/\s*\*\/$|^\s*\*\s{0,1}|^\/\*{1,2}/m', '', $docblock); } diff --git a/src/Reader.php b/src/Reader.php index 0ab3c47..2316cb7 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -136,7 +136,7 @@ public function getConstantAnnotations($class, $const) */ public function getAnnotations(\Reflector $Reflection) { - $doc = $Reflection->getDocComment(); + $doc = (string)$Reflection->getDocComment(); if ($this->cache) { $key = $this->cache->getKey($doc); $ast = $this->cache->get($key); diff --git a/src/Reflector/ReflectionConst.php b/src/Reflector/ReflectionConst.php index 48e7309..936b473 100644 --- a/src/Reflector/ReflectionConst.php +++ b/src/Reflector/ReflectionConst.php @@ -2,6 +2,7 @@ namespace Minime\Annotations\Reflector; +use PhpParser\PhpVersion; use PhpParser\ParserFactory; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; @@ -34,17 +35,18 @@ public function __construct($class, $constName) $className = $classReflection->getName(); $fileName = $classReflection->getFileName(); - $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); + $parser = (new ParserFactory())->createForVersion(PhpVersion::fromString('8.0')); + try { $stmts = $parser->parse(file_get_contents($fileName)); } catch (ParserError $e) { - throw new \ReflectionException("Cannot parse the class ${fileName}", 0, $e); + throw new \ReflectionException("Cannot parse the class {$fileName}", 0, $e); } // Class can be in a namespace or at the root of the statement $classNode = $this->findClassNode($stmts); if (!$classNode) { - throw new \ReflectionException("Class ${className} not found in file ${fileName}"); + throw new \ReflectionException("Class {$className} not found in file {$fileName}"); } @@ -62,7 +64,7 @@ public function __construct($class, $constName) } if (!$this->constNode) { - throw new \ReflectionException("Class constant ${constName} does not exist in class ${className}"); + throw new \ReflectionException("Class constant {$constName} does not exist in class {$className}"); } } diff --git a/test/suite/AnnotationsBagTest.php b/test/suite/AnnotationsBagTest.php index 527e29b..64955c0 100644 --- a/test/suite/AnnotationsBagTest.php +++ b/test/suite/AnnotationsBagTest.php @@ -2,17 +2,20 @@ namespace Minime\Annotations; +use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\Test; use Minime\Annotations\Fixtures\AnnotationConstructInjection; +require_once __DIR__ . '/BaseTestCase.php'; + /** - * @group bag */ -class AnnotationsBagTest extends \PHPUnit_Framework_TestCase +class AnnotationsBagTest extends TestCase { private $Bag; - public function setUp() + public function setUp() : void { $this->Bag = new AnnotationsBag( [ @@ -32,61 +35,59 @@ public function setUp() public function testGet() { - $this->assertSame(false, $this->Bag->get('post')); - $this->assertInstanceOf( + self::assertSame(false, $this->Bag->get('post')); + self::assertInstanceOf( '\Minime\Annotations\Fixtures\AnnotationConstructInjection', $this->Bag->get('Minime\Annotations\Fixtures\AnnotationConstructInjection') ); - $this->assertSame(false, $this->Bag->get('post', true)); - $this->assertSame(null, $this->Bag->get('undefined')); - $this->assertSame(false, $this->Bag->get('undefined', false)); - $this->assertSame([], $this->Bag->get('undefined', [])); + self::assertSame(false, $this->Bag->get('post', true)); + self::assertSame(null, $this->Bag->get('undefined')); + self::assertSame(false, $this->Bag->get('undefined', false)); + self::assertSame([], $this->Bag->get('undefined', [])); } public function testGetAsArray() { // single value - $this->assertSame([false], $this->Bag->getAsArray('put')); - $this->assertCount(1, $this->Bag->getAsArray('put')); + self::assertSame([false], $this->Bag->getAsArray('put')); + self::assertCount(1, $this->Bag->getAsArray('put')); // array value - $this->assertSame(['json', 'csv'], $this->Bag->getAsArray('config.export')); - $this->assertCount(2, $this->Bag->getAsArray('config.export')); + self::assertSame(['json', 'csv'], $this->Bag->getAsArray('config.export')); + self::assertCount(2, $this->Bag->getAsArray('config.export')); // null value - $this->assertSame([null], $this->Bag->getAsArray('default')); - $this->assertCount(1, $this->Bag->getAsArray('default')); + self::assertSame([null], $this->Bag->getAsArray('default')); + self::assertCount(1, $this->Bag->getAsArray('default')); // this value is not set - $this->assertSame([], $this->Bag->getAsArray('foo')); - $this->assertCount(0, $this->Bag->getAsArray('foo')); + self::assertSame([], $this->Bag->getAsArray('foo')); + self::assertCount(0, $this->Bag->getAsArray('foo')); } public function testArrayAccessBag() { $this->Bag = new AnnotationsBag([]); - $this->assertEquals(0, count($this->Bag)); + self::assertEquals(0, count($this->Bag)); $this->Bag['fruit'] = 'orange'; - $this->assertEquals(1, count($this->Bag)); - $this->assertSame('orange', $this->Bag['fruit']); - $this->assertTrue(isset($this->Bag['fruit'])); - $this->assertFalse(isset($this->Bag['cheese'])); + self::assertEquals(1, count($this->Bag)); + self::assertSame('orange', $this->Bag['fruit']); + self::assertTrue(isset($this->Bag['fruit'])); + self::assertFalse(isset($this->Bag['cheese'])); unset($this->Bag['fruit']); - $this->assertEquals(0, count($this->Bag)); - $this->assertNull($this->Bag['fruit']); + self::assertEquals(0, count($this->Bag)); + self::assertNull($this->Bag['fruit']); } - /** - * @test - */ + #[Test] public function grep() { - $this->assertCount(3, $this->Bag->grep('#val#')); - $this->assertCount(2, $this->Bag->grep('#config#')); + self::assertCount(3, $this->Bag->grep('#val#')); + self::assertCount(2, $this->Bag->grep('#config#')); // grep that always matches nothing - $this->assertCount(0, $this->Bag->grep('#^$#')->toArray()); + self::assertCount(0, $this->Bag->grep('#^$#')->toArray()); // chained grep $this->assertSame(['val.max' => 16], $this->Bag->grep('#max$#')->toArray()); @@ -95,9 +96,7 @@ public function grep() $this->assertCount(1, $this->Bag->grep('#Minime\\\Annotations#')->toArray()); } - /** - * @test - */ + #[Test] public function useNamespace() { @@ -147,9 +146,7 @@ public function useNamespace() ); } - /** - * @test - */ + #[Test] public function union() { $this->Bag = new AnnotationsBag( diff --git a/test/suite/BaseTest.php b/test/suite/BaseTestCase.php similarity index 80% rename from test/suite/BaseTest.php rename to test/suite/BaseTestCase.php index 0bee04e..96152d4 100644 --- a/test/suite/BaseTest.php +++ b/test/suite/BaseTestCase.php @@ -3,19 +3,23 @@ namespace Minime\Annotations; use \ReflectionProperty; +use PHPUnit\Framework\TestCase; use Minime\Annotations\Fixtures\AnnotationsFixture; + + /** - * BaseTest + * BaseTestCase + * * */ -abstract class BaseTest extends \PHPUnit_Framework_TestCase +abstract class BaseTestCase extends TestCase { protected $fixture; protected $parser; - public function setUp() + public function setUp(): void { $this->fixture = new AnnotationsFixture; } diff --git a/test/suite/CacheTest.php b/test/suite/CacheTest.php index 0f294a4..c59a1f2 100644 --- a/test/suite/CacheTest.php +++ b/test/suite/CacheTest.php @@ -4,18 +4,22 @@ use Mockery; +use PHPUnit\Framework\TestCase; use Minime\Annotations\Interfaces\CacheInterface; use Minime\Annotations\Cache\FileCache; use Minime\Annotations\Cache\ArrayCache; use Minime\Annotations\Cache\ApcCache; use Minime\Annotations\Fixtures\AnnotationsFixture; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; -class CacheTest extends \PHPUnit_Framework_TestCase +require_once __DIR__ . '/BaseTestCase.php'; + +class CacheTest extends TestCase { protected $fixtureClass = 'Minime\Annotations\Fixtures\AnnotationsFixture'; - public function tearDown() + public function tearDown(): void { Mockery::close(); } @@ -39,35 +43,31 @@ public function testReaderCacheInteraction() $reader = $this->getReader(); $reader->setCache($cache); - $this->assertSame( + self::assertSame( $reader->getPropertyAnnotations($this->fixtureClass, 'inline_docblock_fixture')->get('value'), $reader->getPropertyAnnotations($this->fixtureClass, 'inline_docblock_fixture')->get('value') // from cache ); } public function testArrayCache(){ - $this->assertCacheHandlerWorks(new ArrayCache()); + self::assertCacheHandlerWorks(new ArrayCache()); } public function testFileCache(){ - $this->assertCacheHandlerWorks(new FileCache(__DIR__ . '/../../build/')); + self::assertCacheHandlerWorks(new FileCache(__DIR__ . '/../../build/')); } - public function testFileCacheWithDefaultStoragePath(){ + public function getFileCacheWithDefaultStoragePath(){ new FileCache(); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessageRegExp #^Cache path is not a writable/readable directory: .+\.# - */ public function testFileCacheWithBadStoragePath(){ + $this->expectExceptionMessageMatches("#^Cache path is not a writable/readable directory: .+\.#"); + $this->expectException(\InvalidArgumentException::class); new FileCache(__DIR__ . '/invalid/path/'); } - /** - * @requires extension apc - */ + #[RequiresPhpExtension('apcu')] public function testApcCache(){ $this->assertCacheHandlerWorks(new ApcCache()); } @@ -79,42 +79,42 @@ public function assertCacheHandlerWorks(CacheInterface $cache) $reader->getCache()->clear(); - $this->assertSame( + self::assertSame( $reader->getPropertyAnnotations($this->fixtureClass, 'integer_fixture')->toArray(), $reader->getPropertyAnnotations($this->fixtureClass, 'integer_fixture')->toArray() ); - $this->assertSame( + self::assertSame( $reader->getPropertyAnnotations($this->fixtureClass, 'float_fixture')->toArray(), $reader->getPropertyAnnotations($this->fixtureClass, 'float_fixture')->toArray() ); - $this->assertSame( + self::assertSame( $reader->getPropertyAnnotations($this->fixtureClass, 'namespaced_fixture')->toArray(), $reader->getPropertyAnnotations($this->fixtureClass, 'namespaced_fixture')->toArray() ); - $this->assertSame( + self::assertSame( $reader->getPropertyAnnotations($this->fixtureClass, 'serialize_fixture')->toArray(), $reader->getPropertyAnnotations($this->fixtureClass, 'serialize_fixture')->toArray() ); - $this->assertEquals( + self::assertEquals( $reader->getPropertyAnnotations($this->fixtureClass, 'json_fixture')->toArray(), $reader->getPropertyAnnotations($this->fixtureClass, 'json_fixture')->toArray() ); - $this->assertEquals( + self::assertEquals( $reader->getPropertyAnnotations($this->fixtureClass, 'strong_typed_fixture')->toArray(), $reader->getPropertyAnnotations($this->fixtureClass, 'strong_typed_fixture')->toArray() ); - $this->assertEquals( + self::assertEquals( $reader->getPropertyAnnotations($this->fixtureClass, 'multiline_value_fixture')->toArray(), $reader->getPropertyAnnotations($this->fixtureClass, 'multiline_value_fixture')->toArray() ); - $this->assertEquals( + self::assertEquals( $reader->getPropertyAnnotations($this->fixtureClass, 'concrete_fixture')->toArray(), $reader->getPropertyAnnotations($this->fixtureClass, 'concrete_fixture')->toArray() ); diff --git a/test/suite/DynamicParserTest.php b/test/suite/DynamicParserTestCase.php similarity index 66% rename from test/suite/DynamicParserTest.php rename to test/suite/DynamicParserTestCase.php index 7052d2d..716d2ff 100644 --- a/test/suite/DynamicParserTest.php +++ b/test/suite/DynamicParserTestCase.php @@ -2,102 +2,87 @@ namespace Minime\Annotations; +use PHPUnit\Framework\Attributes\Test; + +require_once __DIR__ . '/BaseTestCase.php'; + /** * DynamicParserTest * - * @group parser */ -class DynamicParserTest extends BaseTest +class DynamicParserTestCase extends BaseTestCase { - public function setUp() + public function setUp(): void { parent::setup(); $this->parser = new DynamicParser; } - /** - * @test - */ + #[Test] public function parseEmptyFixture() { $annotations = $this->getFixture('empty_fixture'); - $this->assertSame([], $annotations); + self::assertSame([], $annotations); } - /** - * @test - */ + #[Test] public function parseNullFixture() { $annotations = $this->getFixture('null_fixture'); - $this->assertSame([null, ''], $annotations['value']); + self::assertSame([null, ''], $annotations['value']); } - /** - * @test - */ + #[Test] public function parseBooleanFixture() { $annotations = $this->getFixture('boolean_fixture'); - $this->assertSame([true, false, "true", "false"], $annotations['value']); + self::assertSame([true, false, "true", "false"], $annotations['value']); } - /** - * @test - */ + #[Test] public function parseImplicitBooleanFixture() { $annotations = $this->getFixture('implicit_boolean_fixture'); - $this->assertSame(true, $annotations['alpha']); - $this->assertSame(true, $annotations['beta']); - $this->assertSame(true, $annotations['gamma']); - $this->assertArrayNotHasKey('delta', $annotations); + self::assertSame(true, $annotations['alpha']); + self::assertSame(true, $annotations['beta']); + self::assertSame(true, $annotations['gamma']); + self::assertArrayNotHasKey('delta', $annotations); } - /** - * @test - */ + #[Test] public function parseStringFixture() { $annotations = $this->getFixture('string_fixture'); - $this->assertSame(['abc', 'abc', 'abc ', '123'], $annotations['value']); - $this->assertSame(['abc', 'abc', 'abc ', '123'], $annotations['value']); + self::assertSame(['abc', 'abc', 'abc ', '123'], $annotations['value']); + self::assertSame(['abc', 'abc', 'abc ', '123'], $annotations['value']); } - /** - * @test - */ + #[Test] public function parseIdentifierFixture() { $annotations = $this->getFixture('identifier_parsing_fixture'); - $this->assertSame(['bar' => 'test@example.com', 'toto' => true, 'tata' => true, 'number' => 2.1], $annotations); + self::assertSame(['bar' => 'test@example.com', 'toto' => true, 'tata' => true, 'number' => 2.1], $annotations); } - /** - * @test - */ + #[Test] public function parseIntegerFixture() { $annotations = $this->getFixture('integer_fixture'); - $this->assertSame([123, 23, -23], $annotations['value']); + self::assertSame([123, 23, -23], $annotations['value']); } - /** - * @test - */ + #[Test] public function parseFloatFixture() { $annotations = $this->getFixture('float_fixture'); - $this->assertSame([.45, 0.45, 45., -4.5], $annotations['value']); + self::assertSame([.45, 0.45, 45., -4.5], $annotations['value']); } - /** - * @test - */ + #[Test] public function parseJsonFixture() { $annotations = $this->getFixture('json_fixture'); - $this->assertEquals( + self::assertEquals( [ ["x", "y"], json_decode('{"x": {"y": "z"}}'), @@ -107,43 +92,35 @@ public function parseJsonFixture() ); } - /** - * @test - */ + #[Test] public function parseSingleValuesFixture() { $annotations = $this->getFixture('single_values_fixture'); - $this->assertEquals('foo', $annotations['param_a']); - $this->assertEquals('bar', $annotations['param_b']); + self::assertEquals('foo', $annotations['param_a']); + self::assertEquals('bar', $annotations['param_b']); } - /** - * @test - */ + #[Test] public function parseMultipleValuesFixture() { $annotations = $this->getFixture('multiple_values_fixture'); - $this->assertEquals(['x', 'y', 'z'], $annotations['value']); + self::assertEquals(['x', 'y', 'z'], $annotations['value']); } - /** - * @test - */ + #[Test] public function parseParseSameLineFixture() { $annotations = $this->getFixture('same_line_fixture'); - $this->assertSame(true, $annotations['get']); - $this->assertSame(true, $annotations['post']); - $this->assertSame(true, $annotations['ajax']); - $this->assertSame(true, $annotations['alpha']); - $this->assertSame(true, $annotations['beta']); - $this->assertSame(true, $annotations['gamma']); - $this->assertArrayNotHasKey('undefined', $annotations); + self::assertSame(true, $annotations['get']); + self::assertSame(true, $annotations['post']); + self::assertSame(true, $annotations['ajax']); + self::assertSame(true, $annotations['alpha']); + self::assertSame(true, $annotations['beta']); + self::assertSame(true, $annotations['gamma']); + self::assertArrayNotHasKey('undefined', $annotations); } - /** - * @test - */ + #[Test] public function parseMultilineValueFixture() { $annotations = $this->getFixture('multiline_value_fixture'); @@ -151,17 +128,15 @@ public function parseMultilineValueFixture() ."Etiam malesuada mauris justo, at sodales nisi accumsan sit amet.\n\n" ."Morbi imperdiet lacus non purus suscipit convallis.\n" ."Suspendisse egestas orci a felis imperdiet, non consectetur est suscipit."; - $this->assertSame($string, $annotations['multiline_string']); + self::assertSame($string, $annotations['multiline_string']); $cowsay = "------\n< moo >\n------ \n \ ^__^\n ". "\ (oo)\_______\n (__)\ )\/\\\n ". "||----w |\n || ||"; - $this->assertSame($cowsay, $annotations['multiline_indented_string']); + self::assertSame($cowsay, $annotations['multiline_indented_string']); } - /** - * @test - */ + #[Test] public function parseNamespacedAnnotations() { $annotations = $this->getFixture('namespaced_fixture'); @@ -171,9 +146,7 @@ public function parseNamespacedAnnotations() $this->assertSame('foo', $annotations['another.path.to.cake']); } - /** - * @test - */ + #[Test] public function parseInlineDocblocks() { $annotations = $this->getFixture('inline_docblock_fixture'); @@ -189,9 +162,9 @@ public function parseInlineDocblocks() } /** - * @test for issue #32 * @link https://github.com/marcioAlmada/annotations/issues/32 */ + #[Test] public function issue32() { $annotations = $this->getFixture('i32_fixture'); @@ -199,9 +172,9 @@ public function issue32() } /** - * @test for issue #49 * @link https://github.com/marcioAlmada/annotations/issues/49 */ + #[Test] public function issue49() { $annotations = $this->getFixture('i49_fixture'); @@ -209,9 +182,9 @@ public function issue49() } /** - * @test for issue #55 * @link https://github.com/marcioAlmada/annotations/issues/55 */ + #[Test] public function issue55() { $annotations = $this->parser->parse($this->getDocblock('i55_fixture')); diff --git a/test/suite/ParserTest.php b/test/suite/ParserTest.php index 55fdb1d..2a73c7a 100644 --- a/test/suite/ParserTest.php +++ b/test/suite/ParserTest.php @@ -3,80 +3,79 @@ namespace Minime\Annotations; use \ReflectionProperty; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\DataProvider; use Minime\Annotations\Fixtures\AnnotationsFixture; +require_once __DIR__ . '/DynamicParserTestCase.php'; + /** * ParserTest * - * @group parser */ -class ParserTest extends DynamicParserTest +class ParserTest extends DynamicParserTestCase { - public function setUp() + public function setUp(): void { parent::setup(); $this->parser = new Parser; } - /** - * @test - */ + #[Test] public function parseConcreteFixture() { $annotations = $this->getFixture('concrete_fixture'); - $this->assertInstanceOf( + self::assertInstanceOf( 'Minime\Annotations\Fixtures\AnnotationConstructInjection', $annotations['Minime\Annotations\Fixtures\AnnotationConstructInjection'][0] ); - $this->assertInstanceOf( + self::assertInstanceOf( 'Minime\Annotations\Fixtures\AnnotationConstructInjection', $annotations['Minime\Annotations\Fixtures\AnnotationConstructInjection'][1] ); - $this->assertSame( + self::assertSame( '{"foo":"bar","bar":"baz"}', json_encode($annotations['Minime\Annotations\Fixtures\AnnotationConstructInjection'][0]) ); - $this->assertSame( + self::assertSame( '{"foo":"bar","bar":"baz"}', json_encode($annotations['Minime\Annotations\Fixtures\AnnotationConstructInjection'][1]) ); - $this->assertSame( + self::assertSame( '{"foo":"foo","bar":"bar"}', json_encode($annotations['Minime\Annotations\Fixtures\AnnotationConstructSugarInjection'][0]) ); - $this->assertSame( + self::assertSame( '{"foo":"baz","bar":"bar"}', json_encode($annotations['Minime\Annotations\Fixtures\AnnotationConstructSugarInjection'][1]) ); - $this->assertInstanceOf( + self::assertInstanceOf( 'Minime\Annotations\Fixtures\AnnotationSetterInjection', $annotations['Minime\Annotations\Fixtures\AnnotationSetterInjection'][0] ); - $this->assertInstanceOf( + self::assertInstanceOf( 'Minime\Annotations\Fixtures\AnnotationSetterInjection', $annotations['Minime\Annotations\Fixtures\AnnotationSetterInjection'][1] ); - $this->assertSame( + self::assertSame( '{"foo":"bar"}', json_encode($annotations['Minime\Annotations\Fixtures\AnnotationSetterInjection'][0]) ); - $this->assertSame( + self::assertSame( '{"foo":"bar"}', json_encode($annotations['Minime\Annotations\Fixtures\AnnotationSetterInjection'][1]) ); } - /** - * @test - * @expectedException \Minime\Annotations\ParserException - * @dataProvider invalidConcreteAnnotationFixtureProvider - */ + #[Test] + #[DataProvider('invalidConcreteAnnotationFixtureProvider')] public function parseInvalidConcreteFixture($fixture) { + $this->expectException(\Minime\Annotations\ParserException::class); $this->getFixture($fixture); } - public function invalidConcreteAnnotationFixtureProvider() + public static function invalidConcreteAnnotationFixtureProvider() { return [ ['bad_concrete_fixture'], @@ -84,15 +83,13 @@ public function invalidConcreteAnnotationFixtureProvider() ]; } - /** - * @test - */ + #[Test] public function parseStrongTypedFixture() { $annotations = $this->getFixture('strong_typed_fixture'); $declarations = $annotations['value']; - $this->assertNotEmpty($declarations); - $this->assertSame( + self::assertNotEmpty($declarations); + self::assertSame( [ "abc", "45", // string 45, -45, // integer @@ -102,7 +99,7 @@ public function parseStrongTypedFixture() ); $declarations = $annotations['json_value']; - $this->assertEquals( + self::assertEquals( [ ["x", "y"], // json json_decode('{"x": {"y": "z"}}'), @@ -112,65 +109,53 @@ public function parseStrongTypedFixture() ); } - /** - * @test - */ + #[Test] public function parseReservedWordsAsValue() { $annotations = $this->getFixture('reserved_words_as_value_fixture'); $expected = ['string','integer','float','json']; - $this->assertSame($expected, $annotations['value']); - $this->assertSame($expected, $annotations['value_with_trailing_space']); + self::assertSame($expected, $annotations['value']); + self::assertSame($expected, $annotations['value_with_trailing_space']); } - /** - * @test - */ + #[Test] public function tolerateUnrecognizedTypes() { $annotations = $this->getFixture('non_recognized_type_fixture'); - $this->assertEquals( + self::assertEquals( "footype Tolerate me. DockBlocks can't be evaluated rigidly.", $annotations['value']); } - /** - * @test - * @expectedException \Minime\Annotations\ParserException - */ + #[Test] public function exceptionWithBadJsonValue() { + $this->expectException(\Minime\Annotations\ParserException::class); $this->getFixture('bad_json_fixture'); } - /** - * @test - * @expectedException \Minime\Annotations\ParserException - */ + #[Test] public function exceptionWithBadIntegerValue() { + $this->expectException(\Minime\Annotations\ParserException::class); $this->getFixture('bad_integer_fixture'); } - /** - * @test - * @expectedException \Minime\Annotations\ParserException - */ + #[Test] public function exceptionWithBadFloatValue() { + $this->expectException(\Minime\Annotations\ParserException::class); $this->getFixture('bad_float_fixture'); } - /** - * @test - */ + #[Test] public function testTypeRegister() { $docblock = '/** @value foo bar */'; - $this->assertSame(['value' => 'foo bar'], $this->parser->parse($docblock)); + self::assertSame(['value' => 'foo bar'], $this->parser->parse($docblock)); $this->parser->registerType('\Minime\Annotations\Fixtures\FooType', 'foo'); - $this->assertSame(['value' => 'this foo is bar'], $this->parser->parse($docblock)); + self::assertSame(['value' => 'this foo is bar'], $this->parser->parse($docblock)); $this->parser->unregisterType('\Minime\Annotations\Fixtures\FooType'); - $this->assertSame(['value' => 'foo bar'], $this->parser->parse($docblock)); + self::assertSame(['value' => 'foo bar'], $this->parser->parse($docblock)); } } diff --git a/test/suite/ReaderTest.php b/test/suite/ReaderTest.php index 34bb0a0..d1a27c0 100644 --- a/test/suite/ReaderTest.php +++ b/test/suite/ReaderTest.php @@ -1,13 +1,14 @@ fixture = new AnnotationsFixture; } @@ -22,49 +23,49 @@ private function getReader() public function testGetReader() { - $this->assertInstanceOf('Minime\Annotations\Interfaces\ParserInterface', $this->getReader()->getParser()); + self::assertInstanceOf('Minime\Annotations\Interfaces\ParserInterface', $this->getReader()->getParser()); } public function testGetAnnotations() { $reflectionClass = new \ReflectionClass($this->fixture); $annotations = $this->getReader()->getAnnotations($reflectionClass); - $this->assertTrue($annotations->get('get')); + self::assertTrue($annotations->get('get')); } public function testReadFunctionAnnotations() { - if(! function_exists($fn = __NAMESPACE__ . '\\fn')){ - /** @bar */ function fn(){} + if(! function_exists($fn = __NAMESPACE__ . '\\testfn')){ + /** @bar */ function testfn(){} } - $this->assertTrue($this->getReader()->getFunctionAnnotations($fn)->get('bar')); + self::assertTrue($this->getReader()->getFunctionAnnotations($fn)->get('bar')); } public function testReadClosureAnnotations() { /** @foo */ $closure = function(){}; - $this->assertTrue($this->getReader()->getFunctionAnnotations($closure)->get('foo')); + self::assertTrue($this->getReader()->getFunctionAnnotations($closure)->get('foo')); } public function testReadClassAnnotations() { $annotations = $this->getReader()->getClassAnnotations($this->fixture); - $this->assertTrue($annotations->get('get')); + self::assertTrue($annotations->get('get')); } public function testReadPropertyAnnotations() { $annotations = $this->getReader()->getPropertyAnnotations($this->fixture, 'single_values_fixture'); - $this->assertEquals('foo', $annotations['param_a']); - $this->assertEquals('bar', $annotations['param_b']); + self::assertEquals('foo', $annotations['param_a']); + self::assertEquals('bar', $annotations['param_b']); } public function testReadMethodAnnotations() { $annotations = $this->getReader()->getMethodAnnotations($this->fixture, 'method_fixture'); - $this->assertTrue($annotations->get('post')); + self::assertTrue($annotations->get('post')); } public function testReadConstantAnnotations() @@ -72,37 +73,37 @@ public function testReadConstantAnnotations() // Single constant with annotation $annotations = $this->getReader()->getConstantAnnotations($this->fixture, "CONSTANT_FIXTURE"); - $this->assertCount(2, $annotations); - $this->assertSame($annotations->get("fix"), 56); - $this->assertTrue($annotations->has("foo")); + self::assertCount(2, $annotations); + self::assertSame($annotations->get("fix"), 56); + self::assertTrue($annotations->has("foo")); // Many constant under the same const declaration with annotation $annotations = $this->getReader()->getConstantAnnotations($this->fixture, "CONSTANT_MANY1"); - $this->assertCount(1, $annotations); - $this->assertSame($annotations->get("value"), "foo"); + self::assertCount(1, $annotations); + self::assertSame($annotations->get("value"), "foo"); // second constant has comment $annotations = $this->getReader()->getConstantAnnotations($this->fixture, "CONSTANT_MANY2"); - $this->assertCount(2, $annotations); - $this->assertSame($annotations->get("value"), "bar"); - $this->assertSame($annotations->get("type"), "constant"); + self::assertCount(2, $annotations); + self::assertSame($annotations->get("value"), "bar"); + self::assertSame($annotations->get("type"), "constant"); // single const with no anntation $annotations = $this->getReader()->getConstantAnnotations($this->fixture, "CONSTANT_EMPTY"); - $this->assertCount(0, $annotations); + self::assertCount(0, $annotations); // Many constant under the same const declaration with no anntation $annotations = $this->getReader()->getConstantAnnotations($this->fixture, "CONSTANT_EMPTY_MANY1"); - $this->assertCount(0, $annotations); + self::assertCount(0, $annotations); // second constant $annotations = $this->getReader()->getConstantAnnotations($this->fixture, "CONSTANT_EMPTY_MANY2"); - $this->assertCount(0, $annotations); + self::assertCount(0, $annotations); // Test case with comment between doc and constant $annotations = $this->getReader()->getConstantAnnotations($this->fixture, "CONSTANT_WITH_COMMENT_BEFORE_DOC"); - $this->assertCount(1, $annotations); + self::assertCount(1, $annotations); $this->assertSame(true, $annotations->get("withComment"));