|
| 1 | +<?php |
| 2 | + |
| 3 | +use Psr\Container\ContainerInterface; |
| 4 | +use Psr\Container\NotFoundExceptionInterface; |
| 5 | +use Technically\NullContainer\Exceptions\ServiceNotFound; |
| 6 | +use Technically\NullContainer\NullContainer; |
| 7 | + |
| 8 | +describe('NullContainer', function() { |
| 9 | + |
| 10 | + it('should instantiate a new instance', function() { |
| 11 | + $container = new NullContainer(); |
| 12 | + assert($container instanceof NullContainer); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should implement PSR container interface', function() { |
| 16 | + $container = new NullContainer(); |
| 17 | + assert($container instanceof ContainerInterface); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('->has()', function() { |
| 21 | + it('should always return false', function () { |
| 22 | + $container = new NullContainer(); |
| 23 | + |
| 24 | + assert($container->has('a') === false); |
| 25 | + assert($container->has('b') === false); |
| 26 | + assert($container->has('c') === false); |
| 27 | + assert($container->has(NullContainer::class) === false); |
| 28 | + assert($container->has(ContainerInterface::class) === false); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('->get()', function() { |
| 33 | + it('should always throw ServiceNotFound exception', function () { |
| 34 | + $container = new NullContainer(); |
| 35 | + |
| 36 | + try { |
| 37 | + $container->get('a'); |
| 38 | + } catch (ServiceNotFound $exception) { |
| 39 | + // passthru |
| 40 | + } |
| 41 | + |
| 42 | + assert(isset($exception)); |
| 43 | + assert($exception instanceof ServiceNotFound); |
| 44 | + assert($exception instanceof NotFoundExceptionInterface); |
| 45 | + }); |
| 46 | + }); |
| 47 | +}); |
0 commit comments