Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit bf9938e

Browse files
authored
fixes #66 (#293)
* fixes #66 * rename and added some classes * added displayer | changed make to create * Added config trait | added uuid | added tests | refator handler * update to http-status v2 * added test for ExceptionInfo * fixed contract and class * adding handler tests * remove shouldReport * Added more tests * Scrutinizer Auto-Fixes (#295) This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com * added more tests * Added filter * Scrutinizer Auto-Fixes (#296) This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com * added more test | add CommandLineTransformer * rename test to tests * Scrutinizer Auto-Fixes (#297) This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com * update tests * added more tests * update phpdoc | changed classes
1 parent 65e4621 commit bf9938e

File tree

86 files changed

+2450
-1186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2450
-1186
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@
4545
"league/flysystem" : "^1.0",
4646
"monolog/monolog" : "^1.17",
4747
"narrowspark/arr" : "^1.0",
48-
"narrowspark/http-status" : "^1.1",
48+
"narrowspark/http-status" : "^2.0",
4949
"php-di/invoker" : "^1.3",
5050
"mpoiriert/invoker" : "^1.1",
5151
"nesbot/carbon" : "^1.21",
5252
"nikic/fast-route" : "^0.6",
53+
"ramsey/uuid" : "^3.4",
5354
"paragonie/constant_time_encoding" : "^2.0",
5455
"paragonie/password_lock" : "^3.0",
5556
"psr/cache" : "^1.0",

phpunit.xml.dist

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
<testsuite name="Narrowspark Events Component Test Suite">
5959
<directory>./src/Viserio/Events/Tests</directory>
6060
</testsuite>
61-
<!-- <testsuite name="Narrowspark Exception Component Test Suite">
61+
<testsuite name="Narrowspark Exception Component Test Suite">
6262
<directory>./src/Viserio/Exception/Tests</directory>
63-
</testsuite> -->
63+
</testsuite>
6464
<testsuite name="Narrowspark Filesystem Component Test Suite">
6565
<directory>./src/Viserio/Filesystem/Tests</directory>
6666
</testsuite>

src/Viserio/Config/Tests/ConfigManagerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Viserio\Config\Test;
2+
namespace Viserio\Config\Tests;
33

44
use org\bovigo\vfs\vfsStream;
55
use Viserio\Config\Manager as ConfigManager;

src/Viserio/Config/Tests/RepositoryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Viserio\Config\Test;
2+
namespace Viserio\Config\Tests;
33

44
use Viserio\Config\Repository;
55

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace Viserio\Config\Tests\Traits;
3+
4+
use Viserio\Config\Manager as ConfigManager;
5+
use Viserio\Config\Repository;
6+
use Viserio\Config\Traits\ConfigAwareTrait;
7+
8+
class ConfigAwareTraitTest extends \PHPUnit_Framework_TestCase
9+
{
10+
use ConfigAwareTrait;
11+
12+
public function testSetAndGetConfig()
13+
{
14+
$this->setConfig(new ConfigManager(new Repository()));
15+
16+
$this->assertInstanceOf(ConfigManager::class, $this->getConfig());
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace Viserio\Config\Traits;
3+
4+
use RuntimeException;
5+
use Viserio\Contracts\Config\Manager as ConfigManagerContract;
6+
7+
trait ConfigAwareTrait
8+
{
9+
/**
10+
* The config instance.
11+
*
12+
* @var \Viserio\Contracts\Config\Manager
13+
*/
14+
protected $config;
15+
16+
/**
17+
* Set a config instance.
18+
*
19+
* @param \Viserio\Contracts\Config\Manager $config
20+
*
21+
* @return self
22+
*/
23+
public function setConfig(ConfigManagerContract $config): self
24+
{
25+
$this->config = $config;
26+
27+
return $this;
28+
}
29+
30+
/**
31+
* Get the config.
32+
*
33+
* @throws \RuntimeException
34+
*
35+
* @return \Viserio\Contracts\Config\Manager
36+
*/
37+
public function getConfig(): ConfigManagerContract
38+
{
39+
if (! $this->config) {
40+
throw new RuntimeException('Config is not set up.');
41+
}
42+
43+
return $this->config;
44+
}
45+
}

src/Viserio/Container/Tests/ContainerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Viserio\Container\Test;
2+
namespace Viserio\Container\Tests;
33

44
use Viserio\Container\Container;
55

src/Viserio/Container/Tests/DefinitionTest.php

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Viserio\Container\Test;
2+
namespace Viserio\Container\Tests;
33

44
use Viserio\Container\Container;
55
use Viserio\Container\Definition;
@@ -31,15 +31,15 @@ public function setUp()
3131
*/
3232
public function testConstruct()
3333
{
34-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Qux');
34+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Qux');
3535
$this->assertAttributeInstanceOf(
3636
'Viserio\\Container\\Container',
3737
'container',
3838
$definition,
3939
'The passed container name should be assigned to the $container property.'
4040
);
4141
$this->assertAttributeEquals(
42-
'Viserio\\Test\\Container\\Qux',
42+
'Viserio\\Tests\\Container\\Qux',
4343
'class',
4444
$definition,
4545
'The passed class name should be assigned to the $class property.'
@@ -51,10 +51,10 @@ public function testConstruct()
5151
*/
5252
public function testInvokeNoArgsOrMethodCalls()
5353
{
54-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Qux');
54+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Qux');
5555
$instance = $definition();
5656
$this->assertInstanceOf(
57-
'Viserio\\Test\\Container\\Qux',
57+
'Viserio\\Tests\\Container\\Qux',
5858
$instance,
5959
'Invoking the Definition class should return an instance of the class $class.'
6060
);
@@ -65,22 +65,22 @@ public function testInvokeNoArgsOrMethodCalls()
6565
*/
6666
public function testInvokeWithArgs()
6767
{
68-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Foo');
69-
$definition->withArgument('Viserio\\Test\\Container\\Bar')->withArgument('Viserio\\Test\\Container\\Baz');
68+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Foo');
69+
$definition->withArgument('Viserio\\Tests\\Container\\Bar')->withArgument('Viserio\\Tests\\Container\\Baz');
7070
$instance = $definition();
7171
$this->assertInstanceOf(
72-
'Viserio\\Test\\Container\\Foo',
72+
'Viserio\\Tests\\Container\\Foo',
7373
$instance,
7474
'Invoking a Definition should return an instance of the class defined in the $class property.'
7575
);
7676
$this->assertAttributeInstanceOf(
77-
'Viserio\\Test\\Container\\Bar',
77+
'Viserio\\Tests\\Container\\Bar',
7878
'bar',
7979
$instance,
8080
'Invoking a Definition with arguments assigned should pass those args to the method.'
8181
);
8282
$this->assertAttributeInstanceOf(
83-
'Viserio\\Test\\Container\\Baz',
83+
'Viserio\\Tests\\Container\\Baz',
8484
'baz',
8585
$instance,
8686
'Invoking a Definition with arguments assigned should pass those args to the method.'
@@ -93,8 +93,8 @@ public function testInvokeWithArgs()
9393
public function testInvokeWithInheritedArgs()
9494
{
9595
$int = rand(1, 5000);
96-
$this->container->bind('Viserio\\Test\\Container\\CorgeInterface')->withArgument($int);
97-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Corge');
96+
$this->container->bind('Viserio\\Tests\\Container\\CorgeInterface')->withArgument($int);
97+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Corge');
9898
$instance = $definition();
9999
$this->assertAttributeEquals(
100100
$int,
@@ -109,11 +109,11 @@ public function testInvokeWithInheritedArgs()
109109
*/
110110
public function testInvokeWithIntegerAsArg()
111111
{
112-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Corge');
112+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Corge');
113113
$definition->withArgument(1);
114114
$instance = $definition();
115115
$this->assertInstanceOf(
116-
'Viserio\\Test\\Container\\Corge',
116+
'Viserio\\Tests\\Container\\Corge',
117117
$instance,
118118
'Invoking a Definition should return an instance of the class defined in the $class property.'
119119
);
@@ -130,16 +130,16 @@ public function testInvokeWithIntegerAsArg()
130130
*/
131131
public function testInvokeWithMethodCall()
132132
{
133-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Qux');
134-
$definition->withMethodCall('setBar', ['Viserio\\Test\\Container\\Bar']);
133+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Qux');
134+
$definition->withMethodCall('setBar', ['Viserio\\Tests\\Container\\Bar']);
135135
$instance = $definition();
136136
$this->assertInstanceOf(
137-
'Viserio\\Test\\Container\\Qux',
137+
'Viserio\\Tests\\Container\\Qux',
138138
$instance,
139139
'Invoking a Definition should return an instance of the class defined in the $class property.'
140140
);
141141
$this->assertAttributeInstanceOf(
142-
'Viserio\\Test\\Container\\Bar',
142+
'Viserio\\Tests\\Container\\Bar',
143143
'bar',
144144
$instance,
145145
'Invoking a Definition with a defined method call pass the defined args to the method.'
@@ -152,9 +152,9 @@ public function testInvokeWithMethodCall()
152152
public function testInvokeWithInheritedMethodCall()
153153
{
154154
$int = rand(1, 5000);
155-
$this->container->bind('Viserio\\Test\\Container\\CorgeInterface')
155+
$this->container->bind('Viserio\\Tests\\Container\\CorgeInterface')
156156
->withMethodCall('setInt', [$int]);
157-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Corge');
157+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Corge');
158158
$instance = $definition();
159159
$this->assertAttributeEquals(
160160
$int,
@@ -169,7 +169,7 @@ public function testInvokeWithInheritedMethodCall()
169169
*/
170170
public function testWithArgument()
171171
{
172-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Foo');
172+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Foo');
173173
$definition->withArgument('foo');
174174
$this->assertAttributeContains(
175175
'foo',
@@ -184,7 +184,7 @@ public function testWithArgument()
184184
*/
185185
public function testAddIntegerArg()
186186
{
187-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Foo');
187+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Foo');
188188
$definition->withArgument(1);
189189
$args = $this->readAttribute($definition, 'arguments');
190190
$this->assertEquals(
@@ -199,7 +199,7 @@ public function testAddIntegerArg()
199199
*/
200200
public function testWithArguments()
201201
{
202-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Foo');
202+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Foo');
203203
$definition->withArguments(['foo', 'bar']);
204204
$this->assertAttributeEquals(
205205
['foo', 'bar'],
@@ -214,7 +214,7 @@ public function testWithArguments()
214214
*/
215215
public function testCleanArgs()
216216
{
217-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Foo');
217+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Foo');
218218
$definition->withArguments(['foo', 'bar']);
219219
$definition->cleanArgument();
220220
$this->assertAttributeEquals(
@@ -227,8 +227,8 @@ public function testCleanArgs()
227227

228228
public function testWithMethod()
229229
{
230-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Qux');
231-
$definition->withMethodCall('setBar', ['Viserio\\Test\\Container\\Bar']);
230+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Qux');
231+
$definition->withMethodCall('setBar', ['Viserio\\Tests\\Container\\Bar']);
232232
$methods = $this->readAttribute($definition, 'methods');
233233
$this->assertArrayHasKey(
234234
'setBar',
@@ -239,7 +239,7 @@ public function testWithMethod()
239239

240240
public function testCallMethod()
241241
{
242-
$definition = new Definition($this->container, 'Viserio\\Test\\Container\\Corge');
242+
$definition = new Definition($this->container, 'Viserio\\Tests\\Container\\Corge');
243243
$definition->withMethodCall('setInt', [1]);
244244
$reflection = new \ReflectionMethod($definition, 'callMethods');
245245
$reflection->setAccessible(true);

src/Viserio/Container/Tests/MockerContainerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Viserio\Container\Test;
2+
namespace Viserio\Container\Tests;
33

44
use Viserio\Container\Container;
55

src/Viserio/Contracts/Exception/Adapter.php

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace Viserio\Contracts\Exception;
3+
4+
use Psr\Http\Message\ResponseInterface;
5+
use Throwable;
6+
7+
interface Displayer
8+
{
9+
/**
10+
* Display the given exception.
11+
*
12+
* @param \Throwable $exception
13+
* @param string $id
14+
* @param int $code
15+
* @param string[] $headers
16+
*
17+
* @return \Psr\Http\Message\ResponseInterface
18+
*/
19+
public function display(Throwable $exception, string $id, int $code, array $headers): ResponseInterface;
20+
21+
/**
22+
* Get the supported content type.
23+
*
24+
* @return string
25+
*/
26+
public function contentType(): string;
27+
28+
/**
29+
* Can we display the exception?
30+
*
31+
* @param \Throwable $original
32+
* @param \Throwable $transformed
33+
* @param int $code
34+
*
35+
* @return bool
36+
*/
37+
public function canDisplay(Throwable $original, Throwable $transformed, int $code): bool;
38+
39+
/**
40+
* Do we provide verbose information about the exception?
41+
*
42+
* @return bool
43+
*/
44+
public function isVerbose(): bool;
45+
}

0 commit comments

Comments
 (0)