forked from phalcon/cphalcon
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[phalcon#12676] - Merge branch '4.0.x' into T12676-add-methods-to-int…
…erfaces * 4.0.x: Merge for phalcon#12547 Added some methods to Phalcon\Acl\Adapter\Memory [phalcon#12295] - Removed the final from the class definition [phalcon#12295] - Updated the changelog [phalcon#12295] - Added container tests [phalcon#12295] - Added Container object, PSR-11 compliant [phalcon#12295] - Added entry to the changelog [phalcon#12295] - Fixed interface [4.0.x] - Another correction to the test
- Loading branch information
Showing
10 changed files
with
271 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <team@phalconphp.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Phalcon\DiInterface; | ||
|
||
class Container implements ContainerInterface | ||
{ | ||
/** | ||
* @var <DiInterface> | ||
*/ | ||
protected container; | ||
|
||
/** | ||
* Phalcon\Di constructor | ||
*/ | ||
public function __construct(<DiInterface> container) | ||
{ | ||
let this->container = container; | ||
} | ||
|
||
/** | ||
* Return the service | ||
*/ | ||
public function get(var name) -> var | ||
{ | ||
return this->container->getService(name); | ||
} | ||
|
||
/** | ||
* Whether a service exists or not in the container | ||
*/ | ||
public function has(var name) -> bool | ||
{ | ||
return this->container->has(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <team@phalconphp.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon\Test\Unit\Container; | ||
|
||
use Phalcon\Container; | ||
use Phalcon\Di; | ||
use Psr\Container\ContainerInterface; | ||
use UnitTester; | ||
|
||
/** | ||
* Class ConstructCest | ||
*/ | ||
class ConstructCest | ||
{ | ||
/** | ||
* Tests Phalcon\Container :: __construct() | ||
* | ||
* @param UnitTester $I | ||
* | ||
* @author Phalcon Team <team@phalconphp.com> | ||
* @since 2018-11-13 | ||
*/ | ||
public function containerConstruct(UnitTester $I) | ||
{ | ||
$I->wantToTest('Container - __construct()'); | ||
|
||
$container = new Di(); | ||
$class = ContainerInterface::class; | ||
$actual = new Container($container); | ||
$I->assertInstanceOf($class, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <team@phalconphp.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon\Test\Unit\Container; | ||
|
||
use Phalcon\Container; | ||
use Phalcon\Di\Service; | ||
use Phalcon\Filter; | ||
use Phalcon\Test\Fixtures\Traits\DiTrait; | ||
use UnitTester; | ||
|
||
/** | ||
* Class GetCest | ||
*/ | ||
class GetCest | ||
{ | ||
use DiTrait; | ||
|
||
/** | ||
* Tests Phalcon\Container :: get() | ||
* | ||
* @param UnitTester $I | ||
* | ||
* @author Phalcon Team <team@phalconphp.com> | ||
* @since 2018-11-13 | ||
*/ | ||
public function containerGet(UnitTester $I) | ||
{ | ||
$I->wantToTest('Container - get()'); | ||
$this->newDi(); | ||
$this->setDiFilter(); | ||
|
||
$container = new Container($this->container); | ||
|
||
/** @var Service $service */ | ||
$service = $container->get('filter'); | ||
$expected = Filter::class; | ||
$actual = $service->getDefinition(); | ||
$I->assertEquals($expected, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <team@phalconphp.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon\Test\Unit\Container; | ||
|
||
use Phalcon\Container; | ||
use Phalcon\Test\Fixtures\Traits\DiTrait; | ||
use UnitTester; | ||
|
||
/** | ||
* Class HasCest | ||
*/ | ||
class HasCest | ||
{ | ||
use DiTrait; | ||
|
||
/** | ||
* Tests Phalcon\Container :: has() | ||
* | ||
* @param UnitTester $I | ||
* | ||
* @author Phalcon Team <team@phalconphp.com> | ||
* @since 2018-11-13 | ||
*/ | ||
public function containerHas(UnitTester $I) | ||
{ | ||
$I->wantToTest('Container - has()'); | ||
$this->newDi(); | ||
$this->setDiFilter(); | ||
|
||
$container = new Container($this->container); | ||
|
||
$actual = $container->has('filter'); | ||
$I->assertTrue($actual); | ||
} | ||
} |