Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 39206de

Browse files
committed
Added more tests to improve library coverage
1 parent c42a0c4 commit 39206de

File tree

6 files changed

+269
-0
lines changed

6 files changed

+269
-0
lines changed

test/ConfigProviderTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-hal for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-hal/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Hal;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Zend\Expressive\Hal\ConfigProvider;
14+
15+
class ConfigProviderTest extends TestCase
16+
{
17+
/**
18+
* @var ConfigProvider
19+
*/
20+
private $provider;
21+
22+
protected function setUp() : void
23+
{
24+
$this->provider = new ConfigProvider();
25+
}
26+
27+
public function testInvocationReturnsArray() : array
28+
{
29+
$config = ($this->provider)();
30+
self::assertInternalType('array', $config);
31+
32+
return $config;
33+
}
34+
35+
/**
36+
* @depends testInvocationReturnsArray
37+
*/
38+
public function testReturnedArrayContainsDependencies(array $config) : void
39+
{
40+
self::assertArrayHasKey('dependencies', $config);
41+
self::assertArrayHasKey('zend-expressive-hal', $config);
42+
self::assertInternalType('array', $config['dependencies']);
43+
}
44+
}

test/ExceptionTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-hal for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-hal/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Hal;
11+
12+
use Generator;
13+
use PHPUnit\Framework\TestCase;
14+
use Zend\Expressive\Hal\Exception\ExceptionInterface;
15+
16+
class ExceptionTest extends TestCase
17+
{
18+
public function exception() : Generator
19+
{
20+
$namespace = substr(ExceptionInterface::class, 0, strrpos(ExceptionInterface::class, '\\') + 1);
21+
22+
$exceptions = glob(__DIR__ . '/../src/Exception/*.php');
23+
foreach ($exceptions as $exception) {
24+
$class = substr(basename($exception), 0, -4);
25+
26+
yield $class => [$namespace . $class];
27+
}
28+
}
29+
30+
/**
31+
* @dataProvider exception
32+
*/
33+
public function testExceptionIsInstanceOfExceptionInterface(string $exception) : void
34+
{
35+
self::assertContains('Exception', $exception);
36+
self::assertTrue(is_a($exception, ExceptionInterface::class, true));
37+
}
38+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-hal for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-hal/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Hal;
11+
12+
use Closure;
13+
use PHPUnit\Framework\TestCase;
14+
use Psr\Container\ContainerInterface;
15+
use Psr\Http\Message\ResponseInterface;
16+
use Psr\Http\Message\StreamInterface;
17+
use Zend\Expressive\Hal\HalResponseFactoryFactory;
18+
use Zend\Expressive\Hal\HalResponseFactory;
19+
use Zend\Expressive\Hal\Renderer;
20+
21+
class HalResponseFactoryFactoryTest extends TestCase
22+
{
23+
public function testReturnsHalResponseFactoryInstance() : void
24+
{
25+
$jsonRenderer = $this->prophesize(Renderer\JsonRenderer::class)->reveal();
26+
$xmlRenderer = $this->prophesize(Renderer\XmlRenderer::class)->reveal();
27+
$response = $this->prophesize(ResponseInterface::class)->reveal();
28+
$stream = new class()
29+
{
30+
public function __invoke()
31+
{
32+
}
33+
};
34+
35+
$container = $this->prophesize(ContainerInterface::class);
36+
$container->has(Renderer\JsonRenderer::class)->willReturn(true);
37+
$container->get(Renderer\JsonRenderer::class)->willReturn($jsonRenderer);
38+
$container->has(Renderer\XmlRenderer::class)->willReturn(true);
39+
$container->get(Renderer\XmlRenderer::class)->willReturn($xmlRenderer);
40+
$container->has(ResponseInterface::class)->willReturn(true);
41+
$container->get(ResponseInterface::class)->willReturn($response);
42+
$container->has(StreamInterface::class)->willReturn(true);
43+
$container->get(StreamInterface::class)->willReturn($stream);
44+
45+
$instance = (new HalResponseFactoryFactory())($container->reveal());
46+
self::assertInstanceOf(HalResponseFactory::class, $instance);
47+
self::assertAttributeSame($jsonRenderer, 'jsonRenderer', $instance);
48+
self::assertAttributeSame($xmlRenderer, 'xmlRenderer', $instance);
49+
self::assertAttributeSame($response, 'responsePrototype', $instance);
50+
self::assertAttributeSame($stream, 'streamFactory', $instance);
51+
}
52+
53+
54+
public function testReturnsHalResponseFactoryInstanceWithoutConfiguredDependencies() : void
55+
{
56+
$container = $this->prophesize(ContainerInterface::class);
57+
$container->has(Renderer\JsonRenderer::class)->willReturn(false);
58+
$container->has(Renderer\XmlRenderer::class)->willReturn(false);
59+
$container->has(ResponseInterface::class)->willReturn(false);
60+
$container->has(StreamInterface::class)->willReturn(false);
61+
62+
$instance = (new HalResponseFactoryFactory())($container->reveal());
63+
self::assertInstanceOf(HalResponseFactory::class, $instance);
64+
self::assertAttributeInstanceOf(Renderer\JsonRenderer::class, 'jsonRenderer', $instance);
65+
self::assertAttributeInstanceOf(Renderer\XmlRenderer::class, 'xmlRenderer', $instance);
66+
self::assertAttributeInstanceOf(ResponseInterface::class, 'responsePrototype', $instance);
67+
self::assertAttributeInstanceOf(Closure::class, 'streamFactory', $instance);
68+
}
69+
}

test/LinkGeneratorFactoryTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-hal for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-hal/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Hal;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Psr\Container\ContainerInterface;
14+
use Zend\Expressive\Hal\LinkGenerator;
15+
use Zend\Expressive\Hal\LinkGeneratorFactory;
16+
17+
class LinkGeneratorFactoryTest extends TestCase
18+
{
19+
public function testReturnsLinkGeneratorInstance() : void
20+
{
21+
$urlGenerator = $this->prophesize(LinkGenerator\UrlGeneratorInterface::class)->reveal();
22+
23+
$container = $this->prophesize(ContainerInterface::class);
24+
$container->get(LinkGenerator\UrlGeneratorInterface::class)->willReturn($urlGenerator);
25+
26+
$instance = (new LinkGeneratorFactory())($container->reveal());
27+
self::assertInstanceOf(LinkGenerator::class, $instance);
28+
self::assertAttributeSame($urlGenerator, 'urlGenerator', $instance);
29+
}
30+
}

test/Metadata/ExceptionTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-hal for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-hal/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Hal\Metadata;
11+
12+
use Generator;
13+
use PHPUnit\Framework\TestCase;
14+
use Zend\Expressive\Hal\Exception\ExceptionInterface as HalExceptionInterface;
15+
use Zend\Expressive\Hal\Metadata\Exception\ExceptionInterface;
16+
17+
class ExceptionTest extends TestCase
18+
{
19+
public function testExceptionInterfaceExtendsHalExceptionInterface() : void
20+
{
21+
self::assertTrue(is_a(ExceptionInterface::class, HalExceptionInterface::class, true));
22+
}
23+
24+
public function exception() : Generator
25+
{
26+
$namespace = substr(ExceptionInterface::class, 0, strrpos(ExceptionInterface::class, '\\') + 1);
27+
28+
$exceptions = glob(__DIR__ . '/../../src/Metadata/Exception/*.php');
29+
foreach ($exceptions as $exception) {
30+
$class = substr(basename($exception), 0, -4);
31+
32+
yield $class => [$namespace . $class];
33+
}
34+
}
35+
36+
/**
37+
* @dataProvider exception
38+
*/
39+
public function testExceptionIsInstanceOfExceptionInterface(string $exception) : void
40+
{
41+
self::assertContains('Exception', $exception);
42+
self::assertTrue(is_a($exception, ExceptionInterface::class, true));
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-hal for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-hal/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Hal\ResourceGenerator;
11+
12+
use Generator;
13+
use PHPUnit\Framework\TestCase;
14+
use Zend\Expressive\Hal\Exception\ExceptionInterface as HalExceptionInterface;
15+
use Zend\Expressive\Hal\ResourceGenerator\Exception\ExceptionInterface;
16+
17+
class ExceptionTest extends TestCase
18+
{
19+
public function testExceptionInterfaceExtendsHalExceptionInterface() : void
20+
{
21+
self::assertTrue(is_a(ExceptionInterface::class, HalExceptionInterface::class, true));
22+
}
23+
24+
public function exception() : Generator
25+
{
26+
$namespace = substr(ExceptionInterface::class, 0, strrpos(ExceptionInterface::class, '\\') + 1);
27+
28+
$exceptions = glob(__DIR__ . '/../../src/ResourceGenerator/Exception/*.php');
29+
foreach ($exceptions as $exception) {
30+
$class = substr(basename($exception), 0, -4);
31+
32+
yield $class => [$namespace . $class];
33+
}
34+
}
35+
36+
/**
37+
* @dataProvider exception
38+
*/
39+
public function testExceptionIsInstanceOfExceptionInterface(string $exception) : void
40+
{
41+
self::assertContains('Exception', $exception);
42+
self::assertTrue(is_a($exception, ExceptionInterface::class, true));
43+
}
44+
}

0 commit comments

Comments
 (0)