From 359568ad6f58b818fad550f7935d127d9edfea65 Mon Sep 17 00:00:00 2001 From: landrok Date: Sat, 6 Apr 2024 16:21:29 +0200 Subject: [PATCH] [QA] Add PHPUnit provider with attributes --- .../ActivityPhp/Server/ConfigurationTest.php | 3 +- tests/ActivityPhp/Server/HelperTest.php | 3 +- tests/ActivityPhp/Server/OutboxPostTest.php | 1 + tests/ActivityPhp/Server/WebFingerTest.php | 13 +++--- .../Type/AttributeFormatValidationTest.php | 2 + tests/ActivityPhp/Type/FactoryTest.php | 41 ++++++++++--------- .../Type/TypesTypeAttributeTest.php | 3 +- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/tests/ActivityPhp/Server/ConfigurationTest.php b/tests/ActivityPhp/Server/ConfigurationTest.php index 0728a2a..140a3ff 100644 --- a/tests/ActivityPhp/Server/ConfigurationTest.php +++ b/tests/ActivityPhp/Server/ConfigurationTest.php @@ -27,6 +27,7 @@ public static function getFailingInstanceScenarios() * Check that all tests are failing * * @dataProvider getFailingInstanceScenarios + * #[DataProvider('getFailingInstanceScenarios')] */ public function testFailingInstanceScenarios($data) { @@ -45,7 +46,7 @@ public function testFailingOnNonExistingParameter() $this->expectException(Exception::class); $config = new Configuration(); - + $config->getConfig('https'); } } diff --git a/tests/ActivityPhp/Server/HelperTest.php b/tests/ActivityPhp/Server/HelperTest.php index 152f9f3..0be341b 100644 --- a/tests/ActivityPhp/Server/HelperTest.php +++ b/tests/ActivityPhp/Server/HelperTest.php @@ -27,12 +27,13 @@ public static function getAcceptHeaderScenarios() 'application/pdf', 'application/json' ], false ], # Refused (array input) - + ]; } /** * @dataProvider getAcceptHeaderScenarios + * #[DataProvider('getAcceptHeaderScenarios')] */ public function testAcceptHeaderScenarios($input, $expected) { diff --git a/tests/ActivityPhp/Server/OutboxPostTest.php b/tests/ActivityPhp/Server/OutboxPostTest.php index 13ee416..5506772 100644 --- a/tests/ActivityPhp/Server/OutboxPostTest.php +++ b/tests/ActivityPhp/Server/OutboxPostTest.php @@ -64,6 +64,7 @@ public static function getOutboxPostActivities() * Check that all response are valid * * @dataProvider getOutboxPostActivities + * #[DataProvider('getOutboxPostActivities')] */ public function testOutboxPostActivities($payload, $accept = 'application/activity+json', $code = 201) { diff --git a/tests/ActivityPhp/Server/WebFingerTest.php b/tests/ActivityPhp/Server/WebFingerTest.php index d73c02f..7f2930d 100644 --- a/tests/ActivityPhp/Server/WebFingerTest.php +++ b/tests/ActivityPhp/Server/WebFingerTest.php @@ -27,7 +27,7 @@ public static function getSuccessScenarios() ] ] ]; - + # handle / method / expected return [ ['bob@localhost:8000', 'toArray', $sample ], # toArray() @@ -80,6 +80,7 @@ public static function getFailingScenarios() * Check that all response are valid * * @dataProvider getSuccessScenarios + * #[DataProvider('getSuccessScenarios')] */ public function testSuccessScenarios($handle, $method, $expected) { @@ -97,7 +98,7 @@ public function testSuccessScenarios($handle, $method, $expected) $webfinger = $server->actor($handle)->webfinger(); - // Assert + // Assert $this->assertEquals( $expected, $webfinger->$method() @@ -108,6 +109,7 @@ public function testSuccessScenarios($handle, $method, $expected) * Check that all tests are failing * * @dataProvider getFailingScenarios + * #[DataProvider('getFailingScenarios')] */ public function testFailingScenarios($handle, $method, $expected) { @@ -125,7 +127,7 @@ public function testFailingScenarios($handle, $method, $expected) ] ]); - + $webfinger = $server->actor($handle)->webfinger(); } @@ -192,6 +194,7 @@ public static function getFailingInstanceScenarios() * Check that all tests are failing * * @dataProvider getFailingInstanceScenarios + * #[DataProvider('getFailingInstanceScenarios')] */ public function testFailingInstanceScenarios($data) { @@ -201,7 +204,7 @@ public function testFailingInstanceScenarios($data) } /** - * Get profile id can return null if webfinger is used for an + * Get profile id can return null if webfinger is used for an * implementation that does not support ActivityPhp */ public function testEmptyProfileId() @@ -222,7 +225,7 @@ public function testEmptyProfileId() $webfinger = new WebFinger($data); - // Assert + // Assert $this->assertEquals( null, $webfinger->getProfileId() diff --git a/tests/ActivityPhp/Type/AttributeFormatValidationTest.php b/tests/ActivityPhp/Type/AttributeFormatValidationTest.php index 561b91f..5942bea 100644 --- a/tests/ActivityPhp/Type/AttributeFormatValidationTest.php +++ b/tests/ActivityPhp/Type/AttributeFormatValidationTest.php @@ -1370,6 +1370,7 @@ public static function getExceptionScenarios() * It checks that getter is working well too. * * @dataProvider getValidAttributesScenarios + * #[DataProvider('getValidAttributesScenarios')] */ public function testValidAttributesScenarios($attr, $type, $value) { @@ -1398,6 +1399,7 @@ public function testValidAttributesScenarios($attr, $type, $value) /** * @dataProvider getExceptionScenarios + * #[DataProvider('getExceptionScenarios')] */ public function testExceptionScenarios($attr, $type, $value) { diff --git a/tests/ActivityPhp/Type/FactoryTest.php b/tests/ActivityPhp/Type/FactoryTest.php index b6f8a65..382cf3b 100644 --- a/tests/ActivityPhp/Type/FactoryTest.php +++ b/tests/ActivityPhp/Type/FactoryTest.php @@ -77,13 +77,14 @@ public static function getShortTypes() /** * Check that all core objects have a correct type property. - * + * * @dataProvider getShortTypes + * #[DataProvider('getShortTypes')] */ public function testShortTypesInstanciation($type) { $class = Type::create($type, ['name' => strtolower($type)]); - + // Assert affectation $this->assertEquals( strtolower($type), @@ -114,7 +115,7 @@ public function testUndefinedType() /** * Scenario for a custom validator - * + * * - Add a validator in the pool for 'customProperty' attribute * - Create a type with this property and affect a correct value */ @@ -123,7 +124,7 @@ public function testCustomValidatorSuccess() Type::add('MyCustomType', MyCustomType::class); Type::addValidator('customProperty', MyCustomValidator::class); $type = Type::create( - 'MyCustomType', + 'MyCustomType', ['customProperty' => 'My value'] ); @@ -135,7 +136,7 @@ public function testCustomValidatorSuccess() } /** - * Scenario for instanciating a Type with a single array parameter + * Scenario for instanciating a Type with a single array parameter */ public function testShortCallSuccess() { @@ -149,7 +150,7 @@ public function testShortCallSuccess() 'Note', $type->type ); - + // Assert another property $this->assertEquals( 'http://example.org/missing-type', @@ -158,7 +159,7 @@ public function testShortCallSuccess() } /** - * Scenario for instanciating a Type with a single array parameter + * Scenario for instanciating a Type with a single array parameter * for a failing value (missing type property) */ public function testShortCallFailing() @@ -184,7 +185,7 @@ public function testShortCallFailingIntGiven() } /** - * Scenario for a custom classes and custom validator with an + * Scenario for a custom classes and custom validator with an * failing value */ public function testCustomValidatorFailing() @@ -193,22 +194,22 @@ public function testCustomValidatorFailing() Type::addValidator('customProperty', MyCustomValidator::class); $type = Type::create( - 'MyCustomType', + 'MyCustomType', ['customProperty' => 'Bad value'] ); } /** * Scenario for a custom type - * + * * - Add a Type in the pool with 'Person' name - * - Instanciate and sets customType value + * - Instanciate and sets customType value */ public function testCustomTypeSuccess() { Type::add('Person', MyCustomType::class); $type = Type::create( - 'Person', + 'Person', ['customProperty' => 'My value'] ); @@ -240,7 +241,7 @@ public function testCopy() ]); $copy = $original->copy(); - + // Assert type are equals $this->assertEquals( $original->type, @@ -252,7 +253,7 @@ public function testCopy() $original->toArray(), $copy->toArray() ); - + // Change a value $copy->id = 'http://example.org/copy-id'; @@ -260,13 +261,13 @@ public function testCopy() $this->assertEquals( 'http://example.org/copy-id', $copy->id - ); + ); // Assert original is not affected $this->assertEquals( 'http://example.org/original-id', $original->id - ); + ); } /** @@ -287,13 +288,13 @@ public function testCopyChaining() $this->assertEquals( 'http://example.org/copy-id', $copy->id - ); + ); // Assert original is not affected $this->assertEquals( 'http://example.org/original-id', $original->id - ); + ); } /** @@ -308,7 +309,7 @@ public function testFromJson() $this->assertEquals( $json, $note->toJson() - ); + ); } /** @@ -328,7 +329,7 @@ public function testFromJsonMalformedJsonString() */ public function testFromJsonNotAnArray() { - $this->expectException(Exception::class); + $this->expectException(Exception::class); $json = '"OK"'; $note = Type::fromJson($json); diff --git a/tests/ActivityPhp/Type/TypesTypeAttributeTest.php b/tests/ActivityPhp/Type/TypesTypeAttributeTest.php index 4f9e2de..f8744a0 100644 --- a/tests/ActivityPhp/Type/TypesTypeAttributeTest.php +++ b/tests/ActivityPhp/Type/TypesTypeAttributeTest.php @@ -127,8 +127,9 @@ public static function getObjectTypeScenarios() /** * Check that all core objects have a correct type property. * It checks that getter is working well too. - * + * * @dataProvider getObjectTypeScenarios + * #[DataProvider('getObjectTypeScenarios')] */ public function testObjectTypeScenarios($type, $attr, $value) {