Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup deprecated test #295

Merged
merged 14 commits into from
Apr 26, 2024
6 changes: 4 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/tests export-ignore
/tests-php8 export-ignore
/tests-deprecated export-ignore
/demo export-ignore
/vendor-bin export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/codecov.yml export-ignore
/composer-require-checker.json export-ignore
/phpcs.xml export-ignore
/phpmd.xml export-ignore
/phpstan.neon export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml export-ignore
/rector.php export-ignore
å
# Configure diff output for .php and .phar files.
*.php diff=php
Expand Down
3 changes: 1 addition & 2 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"Attribute", "ReflectionAttribute", "Stringable",
"BEAR\\Resource\\HalLink", "BEAR\\Resource\\NullReverseLink", "BEAR\\Resource\\ReverseLinkInterface", "BEAR\\Resource\\Module\\AnnotationModule",
"Doctrine\\Common\\Annotations\\Reader", "Doctrine\\Common\\Annotations\\AnnotationReader"
"BEAR\\Resource\\HalLink", "BEAR\\Resource\\NullReverseLink", "BEAR\\Resource\\ReverseLinkInterface", "BEAR\\Resource\\Module\\AnnotationModule"
]
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
"psr-4": {
"BEAR\\Resource\\": [
"tests/",
"tests-php8/",
"tests/Fake/"
"tests/Fake/",
"tests-deprecated"
],
"FakeVendor\\Sandbox\\": "tests/Fake/FakeVendor/Sandbox/",
"FakeVendor\\Blog\\": "tests/Fake/FakeVendor/Blog/src",
"FakeVendor\\News\\": "tests-php8/Fake/News/src"
"FakeVendor\\News\\": "tests/Fake/FakeVendor/News/src"
},
"files": ["tests/Fake/AppInjector.php"]
},
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ parameters:
- '%currentWorkingDirectory%/tests/tmp/*'
- '%currentWorkingDirectory%/tests/Module/tmp/*'
- '%currentWorkingDirectory%/tests/Fake/*'
- tests/HttpResourceObjectTest.php
- tests/HalLinkerTest.php
ignoreErrors:
- '#Access to an undefined property#'
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<testsuites>
<testsuite name="BEAR.Resource Test Suite">
<directory>tests</directory>
<directory>tests-php8</directory>
</testsuite>
</testsuites>
<php>
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<file name="src/OptionsMethodRequest.php"/>
<directory name="vendor" />
<directory name="tests" />
<directory name="tests-php8" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Module/JsonSchemaModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use BEAR\Resource\ResourceObject;
use Ray\Di\AbstractModule;

final class JsonSchemaModule extends AbstractModule
class JsonSchemaModule extends AbstractModule
{
/**
* @param string $jsonSchemaDir Json-schema json file directory
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testBCValidateException()
public function testBCValidateErrorException(JsonSchemaException $e)
{
$expected = '[age] Must have a minimum value of 20';
$this->assertContains($expected, $e->getMessage());
$this->assertStringContainsString($expected, $e->getMessage());
}

public function testException()
Expand Down Expand Up @@ -114,9 +114,9 @@ private function getFakeUsers() : FakeUsers

private function getRo(string $class)
{
$jsonSchema = dirname(__DIR__) . '/Fake/json_schema';
$jsonValidate = dirname(__DIR__) . '/Fake/json_validate';
$ro = (new Injector(new JsonSchemalModule($jsonSchema, $jsonValidate), $_ENV['TMP_DIR']))->getInstance($class);
$jsonSchema = dirname(__DIR__) . '/../tests/Fake/json_schema';
$jsonValidate = dirname(__DIR__) . '/../tests/Fake/json_validate';
$ro = (new Injector(new JsonSchemalModule($jsonSchema, $jsonValidate)))->getInstance($class);
/* @var $ro FakeUser */
$ro->uri = new Uri('app://self/user?id=1');

Expand Down
Empty file removed tests-php8/tmp/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,43 @@
namespace BEAR\Resource;

use BEAR\Resource\Exception\ParameterException;
use Doctrine\Common\Cache\ArrayCache;
use FakeVendor\News\Resource\App\AttrWebContext;
use Koriym\Attributes\AttributeReader;
use PHPUnit\Framework\TestCase;
use Ray\Di\Injector;
use Ray\ServiceLocator\ServiceLocator;

use function call_user_func_array;

class AttrNamedParameterTest extends TestCase
{
private NamedParameter $params;

/** @var FakeAttrContext */
private $ro;

protected function setUp(): void
{
parent::setUp();
$this->params = new NamedParameter(new NamedParamMetas(new AttributeReader()), new Injector());
$this->ro = new AttrWebContext();

$this->params = new NamedParameter(new NamedParamMetas(), new Injector());
}

public function testGetParameters(): void
{
$object = new AttrWebContext();
$namedArgs = ['id' => 1, 'name' => 'koriym'];
$args = $this->params->getParameters([$this->ro, 'onGet'], $namedArgs);
$args = $this->params->getParameters([$object, 'onGet'], $namedArgs);
$this->assertSame(['id' => 1, 'name' => 'koriym'], $args);
}

public function testDefaultValue(): void
{
$object = new AttrWebContext();
$namedArgs = ['id' => 1];
$args = $this->params->getParameters([$this->ro, 'onGet'], $namedArgs);
$args = $this->params->getParameters([$object, 'onGet'], $namedArgs);
$this->assertSame(['id' => 1, 'name' => 'koriym'], $args);
}

public function testParameterException(): void
{
$object = new AttrWebContext();
$this->expectException(ParameterException::class);
$namedArgs = [];
$this->params->getParameters([$this->ro, 'onGet'], $namedArgs);
$this->params->getParameters([$object, 'onGet'], $namedArgs);
}

public function testParameterWebContext(): void
Expand All @@ -64,36 +59,38 @@ public function testParameterWebContext(): void
'env' => 'env_val',
'form' => 'post_val',
'query' => 'get_val',
'server' => 'server_val'
'server' => 'server_val',
];
$args = $this->params->getParameters([$this->ro, 'onPost'], []);
$object = new AttrWebContext();
$args = $this->params->getParameters([$object, 'onPost'], []);
$this->assertSame($expected, $args);
}

public function testParameterWebContextNotExits(): void
{
$this->expectException(ParameterException::class);
AssistedWebContextParam::setSuperGlobalsOnlyForTestingPurpose([]);
$this->params->getParameters([$this->ro, 'onPut'], ['cookie' => 1]); // should be ignored
$object = new AttrWebContext();
$this->params->getParameters([$object, 'onPut'], ['cookie' => 1]); // should be ignored
}

public function testParameterWebContextDefault(): void
{
AssistedWebContextParam::setSuperGlobalsOnlyForTestingPurpose([]);
$expected = [
'a' => 1,
'cookie' => 'default'
'cookie' => 'default',
];
$args = $this->params->getParameters([$this->ro, 'onDelete'], ['a' => 1]);
$object = new AttrWebContext();
$args = $this->params->getParameters([$object, 'onDelete'], ['a' => 1]);
$this->assertSame($expected, $args);
}

public function testParameterWebContexRequiredNotGiven(): void
{
$this->expectException(ParameterException::class);
AssistedWebContextParam::setSuperGlobalsOnlyForTestingPurpose([]);
$this->ro = new FakeParamResource();
$this->params->getParameters([$this->ro, 'onDelete'], []);
$object = new FakeParamResource();
$this->params->getParameters([$object, 'onDelete'], []);
}

}
23 changes: 5 additions & 18 deletions tests-php8/AttributeTest.php → tests/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,22 @@

namespace BEAR\Resource;

use BEAR\Resource\Exception\MethodNotAllowedException;
use BEAR\Resource\Module\HalModule;
use BEAR\Resource\Module\ResourceModule;
use Doctrine\Common\Annotations\AnnotationReader;
use FakeVendor\News\Resource\App\Event;
use FakeVendor\News\Resource\App\News;
use FakeVendor\News\Resource\App\WebParam;
use FakeVendor\Sandbox\Resource\App\Blog;
use FakeVendor\Sandbox\Resource\App\Href\Hasembed;
use FakeVendor\Sandbox\Resource\App\Href\Origin;
use FakeVendor\Sandbox\Resource\App\Href\Target;
use FakeVendor\Sandbox\Resource\Page\Index;
use PHPUnit\Framework\TestCase;
use Ray\Di\Injector;
use Ray\Di\NullModule;

use function assert;
use function var_dump;
use function var_export;

class AttributeTest extends TestCase
{
private \BEAR\Resource\ResourceInterface $resource;
private ResourceInterface $resource;

protected function setUp() : void
protected function setUp(): void
{
parent::setUp();

$injector = new Injector(new ResourceModule('FakeVendor\News'), __DIR__ . '/tmp');
$this->resource = $injector->getInstance(ResourceInterface::class);
}
Expand All @@ -44,9 +33,7 @@ public function testNewInstance(): News
return $instance;
}

/**
* @depends testNewInstance
*/
/** @depends testNewInstance */
public function testEmbeded(News $news): void
{
$ro = $news->onGet('2021/7/23');
Expand All @@ -55,7 +42,6 @@ public function testEmbeded(News $news): void

/**
* @depends testNewInstance
*
* @see ResourceTest::testLinkSelf()
*/
public function testLink(News $news): void
Expand All @@ -66,6 +52,7 @@ public function testLink(News $news): void
$this->assertSame(LinkType::SELF_LINK, $request->links[0]->type);
$ro = $request();
$this->assertSame(200, $ro->code);
$this->assertIsArray($ro->body);
$this->assertArrayHasKey('event', $ro->body);
$this->assertSame('2021/7/23', $ro->body['event']);
}
Expand Down
5 changes: 0 additions & 5 deletions tests/NamedParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public function testCameCaseParam(): void
$this->assertSame(['userId' => 'koriym', 'userRole' => 'lead'], (array) $ro->body);
}

/** @requires PHP >= 8.1 */
public function testEnumParam(): void
{
$ro = new EnumParam();
Expand All @@ -130,7 +129,6 @@ public function testEnumParam(): void
);
}

/** @requires PHP >= 8.1 */
public function testEnumInvlidType(): void
{
$this->expectException(ParameterEnumTypeException::class);
Expand All @@ -140,7 +138,6 @@ public function testEnumInvlidType(): void
$this->params->getParameters([$ro, 'onGet'], $params);
}

/** @requires PHP >= 8.1 */
public function testWithResourceClient(): void
{
$resource = (new Injector(new ResourceModule('FakeVendor\Sandbox')))->getInstance(ResourceInterface::class);
Expand All @@ -150,7 +147,6 @@ public function testWithResourceClient(): void
$this->assertSame(['stringBacked' => 'foo', 'intBacked' => 1], $body);
}

/** @requires PHP >= 8.1 */
public function testEnumParamWithResourceClient(): void
{
$this->expectException(ParameterInvalidEnumException::class);
Expand All @@ -160,7 +156,6 @@ public function testEnumParamWithResourceClient(): void
$resource->get('page://self/enum-param', $params);
}

/** @requires PHP >= 8.1 */
public function testNotBackedEnumParamWithResourceClient(): void
{
$this->expectException(NotBackedEnumException::class);
Expand Down
3 changes: 0 additions & 3 deletions tests/ShortSyntaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ protected function setUp(): void
$this->resource = $injector->getInstance(ResourceInterface::class);
}

/** @requires PHP 7.0.0 */
public function testShortSyntax(): void
{
$ro = $this->resource->get('page://self/index', ['id' => 'koriym']);
$this->assertInstanceOf(Index::class, $ro);
$this->assertSame('koriym', $ro->body);
}

/** @requires PHP 7.0.0 */
public function testShortSyntaxWithQuery(): void
{
$ro = $this->resource->get->uri('page://self/index?id=koriym')();
Expand Down Expand Up @@ -63,7 +61,6 @@ public function testShortSyntaxReuseRequest(AbstractRequest $index): void
$this->assertSame('bear', $ro->body);
}

/** @requires PHP 7.0.0 */
public function testShortSyntaxFunctionWithDefaultGetMethod(): void
{
$ro = $this->resource->uri('page://self/index')();
Expand Down
Loading