Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Devlamynck committed Feb 26, 2024
1 parent 67fb062 commit 5b7f98a
Show file tree
Hide file tree
Showing 12 changed files with 565 additions and 1,257 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?php declare(strict_types=1);

namespace RichCongress\TestFramework\TestConfiguration\Annotation;
namespace RichCongress\TestFramework\TestConfiguration\Attribute;

/**
* Class TestConfig
*
* @package RichCongress\TestFramework\TestConfiguration
* @author Nicolas Guilloux <[email protected]>
* @copyright 2014 - 2020 RichCongress (https://www.richcongress.com)
*
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class TestConfig
Expand Down
2 changes: 1 addition & 1 deletion TestConfiguration/TestConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RichCongress\TestFramework\TestConfiguration;

use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;

/**
* Class TestConfiguration
Expand Down
36 changes: 3 additions & 33 deletions TestConfiguration/TestConfigurationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace RichCongress\TestFramework\TestConfiguration;

use Doctrine\Common\Annotations\AnnotationReader;
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;

/**
* Class TestConfigurationExtractor
Expand All @@ -14,9 +13,6 @@
*/
final class TestConfigurationExtractor
{
/** @var AnnotationReader */
private static $annotationReader;

public static function get(string $class, string $method): ?TestConfig
{
$reflectionClass = new \ReflectionClass($class);
Expand Down Expand Up @@ -46,34 +42,8 @@ public static function getRecursively(string $class, string $method): ?TestConfi
: null;
}

public static function getFromReflection(\Reflector $reflection): ?TestConfig
{
if (method_exists($reflection, 'getAttributes')) {
$attribute = $reflection->getAttributes(TestConfig::class)[0] ?? null;

if ($attribute !== null) {
return $attribute->newInstance();
}
}

switch (\get_class($reflection)) {
case \ReflectionClass::class:
return self::getAnnotationReader()->getClassAnnotation($reflection, TestConfig::class);

case \ReflectionMethod::class:
return self::getAnnotationReader()->getMethodAnnotation($reflection, TestConfig::class);

default:
throw new \LogicException('Unsupported reflector.');
}
}

private static function getAnnotationReader(): AnnotationReader
public static function getFromReflection(\ReflectionMethod|\ReflectionClass $reflection): ?TestConfig
{
if (self::$annotationReader === null) {
self::$annotationReader = new AnnotationReader();
}

return self::$annotationReader;
return ($reflection->getAttributes(TestConfig::class)[0] ?? null)?->newInstance();
}
}
2 changes: 1 addition & 1 deletion TestHook/TestConfigurationHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RichCongress\TestFramework\TestHook;

use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;
use RichCongress\TestFramework\TestConfiguration\TestConfiguration;
use RichCongress\TestFramework\TestConfiguration\TestConfigurationExtractor;

Expand Down
11 changes: 5 additions & 6 deletions Tests/Resources/DummyTestCaseWithTestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
namespace RichCongress\TestFramework\Tests\Resources;

use PHPUnit\Framework\TestCase;
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;

/**
* Class DummyTestCaseWithTestConfig
*
* @package RichCongress\TestFramework\Tests\Resources
* @author Nicolas Guilloux <[email protected]>
* @copyright 2014 - 2020 RichCongress (https://www.richcongress.com)
*
* @TestConfig({
* "test_case_configuration": "this is a test",
* "test_case_configuration_2": 10
* })
*/
#[TestConfig([
'test_case_configuration' => 'this is a test',
'test_case_configuration_2' => 10
])]
abstract class DummyTestCaseWithTestConfig extends TestCase
{
}
17 changes: 2 additions & 15 deletions Tests/TestConfiguration/TestConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace RichCongress\TestFramework\Tests\TestConfiguration;

use PHPUnit\Framework\TestCase;
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;
use RichCongress\TestFramework\TestConfiguration\TestConfiguration;
use RichCongress\TestFramework\TestConfiguration\TestConfigurationExtractor;

Expand All @@ -19,9 +19,7 @@
*/
final class TestConfigurationTest extends TestCase
{
/**
* @TestConfig("custom_configuration")
*/
#[TestConfig('custom_configuration')]
public function testTestConfiguration(): void
{
$testConfig = TestConfigurationExtractor::get(__CLASS__, __FUNCTION__);
Expand All @@ -40,15 +38,4 @@ public function testGetFromReflectionWithAttribute(): void

self::assertNotNull($testConfig);
}

public function testGetFromReflectionWithUnknownReflector(): void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Unsupported reflector.');

$reflector = new \ReflectionObject(new \StdClass());
$testConfig = TestConfigurationExtractor::getFromReflection($reflector);

self::assertNotNull($testConfig);
}
}
10 changes: 4 additions & 6 deletions Tests/TestConfiguration/WithClassConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RichCongress\TestFramework\Tests\TestConfiguration;

use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;
use RichCongress\TestFramework\TestConfiguration\TestConfigurationExtractor;
use RichCongress\TestFramework\Tests\Resources\DummyTestCaseWithTestConfig;

Expand All @@ -13,15 +13,13 @@
* @author Nicolas Guilloux <[email protected]>
* @copyright 2014 - 2020 RichCongress (https://www.richcongress.com)
*
* @covers \RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig
* @covers \RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig
* @covers \RichCongress\TestFramework\TestConfiguration\TestConfigurationExtractor
* @TestConfig("test_class_configuration")
*/
#[TestConfig('test_class_configuration')]
final class WithClassConfigTest extends DummyTestCaseWithTestConfig
{
/**
* @TestConfig("test_method_configuration")
*/
#[TestConfig('test_method_configuration')]
public function testWithTestConfig(): void
{
$testConfig = TestConfigurationExtractor::getRecursively(__CLASS__, __FUNCTION__);
Expand Down
8 changes: 3 additions & 5 deletions Tests/TestConfiguration/WithTestCaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RichCongress\TestFramework\Tests\TestConfiguration;

use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;
use RichCongress\TestFramework\TestConfiguration\TestConfigurationExtractor;
use RichCongress\TestFramework\Tests\Resources\DummyTestCaseWithTestConfig;

Expand All @@ -13,14 +13,12 @@
* @author Nicolas Guilloux <[email protected]>
* @copyright 2014 - 2020 RichCongress (https://www.richcongress.com)
*
* @covers \RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig
* @covers \RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig
* @covers \RichCongress\TestFramework\TestConfiguration\TestConfigurationExtractor
*/
final class WithTestCaseConfigTest extends DummyTestCaseWithTestConfig
{
/**
* @TestConfig("test_method_configuration")
*/
#[TestConfig('test_method_configuration')]
public function testWithTestConfig(): void
{
$testConfig = TestConfigurationExtractor::getRecursively(__CLASS__, __FUNCTION__);
Expand Down
8 changes: 3 additions & 5 deletions Tests/TestConfiguration/WithoutClassConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace RichCongress\TestFramework\Tests\TestConfiguration;

use PHPUnit\Framework\TestCase;
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;
use RichCongress\TestFramework\TestConfiguration\TestConfigurationExtractor;

/**
Expand All @@ -13,14 +13,12 @@
* @author Nicolas Guilloux <[email protected]>
* @copyright 2014 - 2020 RichCongress (https://www.richcongress.com)
*
* @covers \RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig
* @covers \RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig
* @covers \RichCongress\TestFramework\TestConfiguration\TestConfigurationExtractor
*/
final class WithoutClassConfigTest extends TestCase
{
/**
* @TestConfig("test_method_configuration")
*/
#[TestConfig('test_method_configuration')]
public function testWithTestConfig(): void
{
$testConfig = TestConfigurationExtractor::getRecursively(__CLASS__, __FUNCTION__);
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
"issues": "https://github.com/richcongress/test-framework/issues"
},
"require": {
"php": "^7.1|^8.0",
"doctrine/annotations": "^1.11",
"phpunit/phpunit": "^7|^8|^9"
"php": "^8.1",
"phpunit/phpunit": "^9.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand All @@ -29,7 +28,7 @@
"RichCongress\\TestFramework\\": ""
},
"files" : [
"TestConfiguration/Annotation/TestConfig.php"
"TestConfiguration/Attribute/TestConfig.php"
]
},
"autoload-dev": {
Expand Down
Loading

0 comments on commit 5b7f98a

Please sign in to comment.