Skip to content

Commit

Permalink
#16 has() method doesn't look at $resolved values
Browse files Browse the repository at this point in the history
  • Loading branch information
renakdup committed Aug 20, 2024
1 parent 28f56ca commit 91c284f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
[![UnitTests](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpunit.yaml/badge.svg)](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpunit.yaml)
[![Test Coverage](https://api.codeclimate.com/v1/badges/21ae6e3776b160b24e75/test_coverage)](https://codeclimate.com/github/renakdup/simple-php-dic/test_coverage)
[![PHPStan](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpstan.yaml/badge.svg)](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpstan.yaml)
[![Latest Stable Version](http://poser.pugx.org/renakdup/simple-dic/v)](https://packagist.org/packages/renakdup/simple-dic)
[![PHP Version Require](http://poser.pugx.org/renakdup/simple-dic/require/php)](https://packagist.org/packages/renakdup/simple-dic)
[![Total Downloads](http://poser.pugx.org/renakdup/simple-dic/downloads)](https://packagist.org/packages/renakdup/simple-dic)

[//]: # ([![Latest Stable Version](http://poser.pugx.org/renakdup/simple-dic/v)](https://packagist.org/packages/renakdup/simple-dic))

[//]: # ([![PHP Version Require](http://poser.pugx.org/renakdup/simple-dic/require/php)](https://packagist.org/packages/renakdup/simple-dic))

[//]: # ([![Total Downloads](http://poser.pugx.org/renakdup/simple-dic/downloads)](https://packagist.org/packages/renakdup/simple-dic))

Simple DI Container with **autowiring** in a single file **with NO dependencies** allows you to easily use it in your PHP applications and especially convenient for **WordPress** plugins and themes.

Expand Down
5 changes: 2 additions & 3 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Author Email: [email protected]
* Author Site: https://wp-yoda.com/en/
*
* Version: 1.1.2
* Version: 1.2.2
* Source Code: https://github.com/renakdup/simple-dic
*
* Licence: MIT License
Expand Down Expand Up @@ -80,7 +80,6 @@ public function get( string $id ) {
}

$service = $this->resolve( $id );

$this->resolved[ $id ] = $service;

return $service;
Expand All @@ -98,7 +97,7 @@ public function get( string $id ) {
* @return bool
*/
public function has( string $id ): bool {
return array_key_exists( $id, $this->services );
return array_key_exists( $id, $this->resolved ) || array_key_exists( $id, $this->services );
}

/**
Expand Down
15 changes: 7 additions & 8 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use RenakdupTests\SimpleDIC\Assets\ClassWithConstructor;
use RenakdupTests\SimpleDIC\Assets\ClassWithConstructorDepsException;
use RenakdupTests\SimpleDIC\Assets\ParentClass;
use RenakdupTests\SimpleDIC\Assets\PrivateConstructor;
use RenakdupTests\SimpleDIC\Assets\SomeInterface;
use RenakdupTests\SimpleDIC\Assets\SimpleClass;
use RenakdupTests\SimpleDIC\Assets\UseAbstractClass;
Expand Down Expand Up @@ -124,9 +123,7 @@ public function test_get__singleton_check_changing_property(): void {
}

public function test_get__singleton_for_resolved_child_dependencies(): void {
/**
* @var $obj1 ClassWithConstructor
*/
/** @var ClassWithConstructor $obj1 */
$obj1 = $this->container->get( ClassWithConstructor::class );

self::assertSame(
Expand Down Expand Up @@ -211,11 +208,9 @@ public function test_get__error_for_not_bound_supertypes(): void {
}

public function test_make(): void {
/**
* @var $obj1 ClassWithConstructorPrimitives
* @var $obj2 ClassWithConstructorPrimitives
*/
/** @var ClassWithConstructorPrimitives $obj1 */
$obj1 = $this->container->make( ClassWithConstructorPrimitives::class );
/** @var ClassWithConstructorPrimitives $obj2 */
$obj2 = $this->container->make( ClassWithConstructorPrimitives::class );

self::assertNotSame( $obj1, $obj2 );
Expand Down Expand Up @@ -250,5 +245,9 @@ public function test_has(): void {

self::assertTrue( $this->container->has( $name ) );
self::assertFalse( $this->container->has( 'not-exist' ) );

$this->container->get( SimpleClass::class );
self::assertTrue( $this->container->has( SimpleClass::class ) );
}

}

0 comments on commit 91c284f

Please sign in to comment.