-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimpleSentryFactoryTest.php
More file actions
140 lines (129 loc) · 4.2 KB
/
SimpleSentryFactoryTest.php
File metadata and controls
140 lines (129 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
declare(strict_types = 1);
namespace Consistence\Sentry\Factory\Simple;
use Consistence\Sentry\Metadata\SentryIdentificator;
use Consistence\Sentry\SentryIdentificatorParser\SentryIdentificatorParser;
use Consistence\Sentry\Type\CollectionType;
use Consistence\Sentry\Type\Sentry;
use Consistence\Sentry\Type\SimpleType;
use Generator;
use PHPUnit\Framework\Assert;
class SimpleSentryFactoryTest extends \PHPUnit\Framework\TestCase
{
/**
* @return mixed[][]|\Generator
*/
public function sentryIdentificatorToSentryDataProvider(): Generator
{
yield 'string' => [
'sentryIdentificator' => new SentryIdentificator('string'),
'sentry' => new SimpleType(),
];
yield 'int' => [
'sentryIdentificator' => new SentryIdentificator('int'),
'sentry' => new SimpleType(),
];
yield 'bool' => [
'sentryIdentificator' => new SentryIdentificator('bool'),
'sentry' => new SimpleType(),
];
yield 'float' => [
'sentryIdentificator' => new SentryIdentificator('float'),
'sentry' => new SimpleType(),
];
yield 'integer' => [
'sentryIdentificator' => new SentryIdentificator('integer'),
'sentry' => new SimpleType(),
];
yield 'boolean' => [
'sentryIdentificator' => new SentryIdentificator('boolean'),
'sentry' => new SimpleType(),
];
yield 'mixed' => [
'sentryIdentificator' => new SentryIdentificator('mixed'),
'sentry' => new SimpleType(),
];
yield 'object' => [
'sentryIdentificator' => new SentryIdentificator('DateTimeImmutable'),
'sentry' => new SimpleType(),
];
yield 'string array' => [
'sentryIdentificator' => new SentryIdentificator('string[]'),
'sentry' => new CollectionType(),
];
yield 'int array' => [
'sentryIdentificator' => new SentryIdentificator('int[]'),
'sentry' => new CollectionType(),
];
yield 'bool array' => [
'sentryIdentificator' => new SentryIdentificator('bool[]'),
'sentry' => new CollectionType(),
];
yield 'float array' => [
'sentryIdentificator' => new SentryIdentificator('float[]'),
'sentry' => new CollectionType(),
];
yield 'integer array' => [
'sentryIdentificator' => new SentryIdentificator('integer[]'),
'sentry' => new CollectionType(),
];
yield 'boolean array' => [
'sentryIdentificator' => new SentryIdentificator('boolean[]'),
'sentry' => new CollectionType(),
];
yield 'mixed array' => [
'sentryIdentificator' => new SentryIdentificator('mixed[]'),
'sentry' => new CollectionType(),
];
yield 'object array' => [
'sentryIdentificator' => new SentryIdentificator('DateTimeImmutable[]'),
'sentry' => new CollectionType(),
];
}
/**
* @dataProvider sentryIdentificatorToSentryDataProvider
*
* @param \Consistence\Sentry\Metadata\SentryIdentificator $sentryIdentificator
* @param \Consistence\Sentry\Type\Sentry $sentry
*/
public function testGetSentry(SentryIdentificator $sentryIdentificator, Sentry $sentry): void
{
$factory = new SimpleSentryFactory(new SentryIdentificatorParser());
Assert::assertTrue($factory->getSentry($sentryIdentificator) instanceof $sentry);
}
public function testSameSentryInstance(): void
{
$factory = new SimpleSentryFactory(new SentryIdentificatorParser());
$sentry = $factory->getSentry(new SentryIdentificator('string'));
Assert::assertSame($sentry, $factory->getSentry(new SentryIdentificator('string')));
}
/**
* @return mixed[][]|\Generator
*/
public function getSentryWhenNoSentryForIdentificatorDataProvider(): Generator
{
yield 'empty string' => [
'sentryIdentificator' => new SentryIdentificator(''),
];
yield 'nonexistent object' => [
'sentryIdentificator' => new SentryIdentificator('Foo\Bar'),
];
}
/**
* @dataProvider getSentryWhenNoSentryForIdentificatorDataProvider
*
* @param \Consistence\Sentry\Metadata\SentryIdentificator $sentryIdentificator
*/
public function testGetSentryWhenNoSentryForIdentificator(
SentryIdentificator $sentryIdentificator
): void
{
$factory = new SimpleSentryFactory(new SentryIdentificatorParser());
try {
$factory->getSentry($sentryIdentificator);
Assert::fail('Exception expected');
} catch (\Consistence\Sentry\Factory\NoSentryForIdentificatorException $e) {
Assert::assertSame($sentryIdentificator, $e->getSentryIdentificator());
}
}
}