Skip to content

Commit

Permalink
Change order when checking instance from ReflectionContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Jan 12, 2024
1 parent e957b92 commit 072cb7f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Container/ReflectionContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function get($id)
throw new Exception\NotFoundException(sprintf($message, $id));
}

if ($this->container && $this->container->has($id))
{
return $this->container->get((string) $id);
}

/** @var class-string $id */
$reflection = new \ReflectionClass((string) $id);

Expand All @@ -57,11 +62,6 @@ public function get($id)
return $reflection->newInstanceArgs($arguments);
}

if ($this->container && $this->container->has($id))
{
return $this->container->get((string) $id);
}

return new $id;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Application/ApplicationTestCases.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
class ApplicationTestCases extends Testcase
{
/**
* @var string
*/
protected $type = '';

/**
* @var \Rougin\Slytherin\System
*/
Expand Down Expand Up @@ -160,6 +165,11 @@ public function test_response_using_response_interface()
*/
public function test_response_with_mutated_server_request()
{
if ($this->type === 'auryn')
{
$this->markTestSkipped('Dynamic request must be shared again if using Auryn.');
}

$data = array('test' => 'Hello with request');

$request = $this->request('GET', '/request', $data);
Expand Down
11 changes: 8 additions & 3 deletions tests/Application/AurynContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
class AurynContainerTest extends ApplicationTestCases
{
/**
* @var string
*/
protected $type = 'auryn';

/**
* @return void
*/
Expand All @@ -31,15 +36,15 @@ protected function doSetUp()

$router = $this->router();

$container->share(new Dispatcher($router));
$container->alias(System::DISPATCHER, 'Rougin\Slytherin\Routing\Dispatcher');

$container->share($this->request('GET', '/'));
$container->alias(System::REQUEST, 'Rougin\Slytherin\Http\ServerRequest');

$container->share(new Response);
$container->alias(System::RESPONSE, 'Rougin\Slytherin\Http\Response');

$container->share(new Dispatcher($router));
$container->alias(System::DISPATCHER, 'Rougin\Slytherin\Routing\Dispatcher');

$container->share(new Middleware);
$container->alias(System::MIDDLEWARE, 'Rougin\Slytherin\Middleware\Dispatcher');

Expand Down

0 comments on commit 072cb7f

Please sign in to comment.