Skip to content

Commit a44bcc2

Browse files
committed
Fixed atMost, Bumped dependencies, added test for universal options in ObjectConstraint
1 parent dbd5141 commit a44bcc2

File tree

5 files changed

+213
-19
lines changed

5 files changed

+213
-19
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
"require": {
1515
"php": ">=8.0.1",
1616
"ext-fileinfo": "*",
17-
"infinityloop-dev/graphpinator": "^1.2",
17+
"infinityloop-dev/graphpinator": "^1.2.1",
1818
"infinityloop-dev/utils": "^2.1.2",
1919
"nette/utils": "^3.2"
2020
},
2121
"require-dev": {
2222
"infinityloop-dev/graphpinator-upload": "^1.0.2",
2323
"phpunit/phpunit": "^9.5",
2424
"infection/infection": "^0.25",
25-
"phpstan/phpstan": "^0.12 || ^1.0",
25+
"phpstan/phpstan": "^1.0",
2626
"infinityloop-dev/coding-standard": "^0.2"
2727
},
2828
"suggest": {

composer.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ObjectConstraintDirective.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private static function resolveAtMost(
193193
++$currentCount;
194194
}
195195

196-
if ($currentCount >= $count) {
196+
if ($currentCount > $count) {
197197
throw new Exception\AtMostConstraintNotSatisfied();
198198
}
199199
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Graphpinator\ConstraintDirectives\Tests\Integration;
6+
7+
final class ObjectConstraintTest extends \PHPUnit\Framework\TestCase
8+
{
9+
public function testAtLeastValidExactly() : void
10+
{
11+
$value = self::getAtLeastInput()->accept(
12+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => 'Value'], new \Graphpinator\Common\Path()),
13+
);
14+
\assert($value instanceof \Graphpinator\Value\InputValue);
15+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
16+
17+
self::assertInstanceOf(\Graphpinator\Value\InputValue::class, $value);
18+
}
19+
20+
public function testAtLeastValidMore() : void
21+
{
22+
$value = self::getAtLeastInput()->accept(
23+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => 'Value', 'arg2' => 'Value'], new \Graphpinator\Common\Path()),
24+
);
25+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
26+
27+
self::assertInstanceOf(\Graphpinator\Value\InputValue::class, $value);
28+
}
29+
30+
public function testAtLeastInvalid() : void
31+
{
32+
$this->expectException(\Graphpinator\ConstraintDirectives\Exception\AtLeastConstraintNotSatisfied::class);
33+
34+
$value = self::getAtLeastInput()->accept(
35+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => null, 'arg2' => null], new \Graphpinator\Common\Path()),
36+
);
37+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
38+
}
39+
40+
public function testAtMostValidExactly() : void
41+
{
42+
$value = self::getAtMostInput()->accept(
43+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => 'Value'], new \Graphpinator\Common\Path()),
44+
);
45+
\assert($value instanceof \Graphpinator\Value\InputValue);
46+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
47+
48+
self::assertInstanceOf(\Graphpinator\Value\InputValue::class, $value);
49+
}
50+
51+
public function testAtMostValidLess() : void
52+
{
53+
$value = self::getAtMostInput()->accept(
54+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => null, 'arg2' => null], new \Graphpinator\Common\Path()),
55+
);
56+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
57+
58+
self::assertInstanceOf(\Graphpinator\Value\InputValue::class, $value);
59+
}
60+
61+
public function testAtMostInvalid() : void
62+
{
63+
$this->expectException(\Graphpinator\ConstraintDirectives\Exception\AtMostConstraintNotSatisfied::class);
64+
65+
$value = self::getAtMostInput()->accept(
66+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => 'Value', 'arg2' => 'Value'], new \Graphpinator\Common\Path()),
67+
);
68+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
69+
}
70+
71+
public function testExactlyValidEmpty() : void
72+
{
73+
$value = self::getExactlyInput()->accept(
74+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => 'Value'], new \Graphpinator\Common\Path()),
75+
);
76+
\assert($value instanceof \Graphpinator\Value\InputValue);
77+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
78+
79+
self::assertInstanceOf(\Graphpinator\Value\InputValue::class, $value);
80+
}
81+
82+
public function testExactlyValidNull() : void
83+
{
84+
$value = self::getExactlyInput()->accept(
85+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => 'Value', 'arg2' => null], new \Graphpinator\Common\Path()),
86+
);
87+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
88+
89+
self::assertInstanceOf(\Graphpinator\Value\InputValue::class, $value);
90+
}
91+
92+
public function testExactlyInvalid() : void
93+
{
94+
$this->expectException(\Graphpinator\ConstraintDirectives\Exception\ExactlyConstraintNotSatisfied::class);
95+
96+
$value = self::getExactlyInput()->accept(
97+
new \Graphpinator\Value\ConvertRawValueVisitor((object) ['arg1' => 'Value', 'arg2' => 'Value'], new \Graphpinator\Common\Path()),
98+
);
99+
$value->applyVariables(new \Graphpinator\Normalizer\VariableValueSet([]));
100+
}
101+
102+
private static function getAtLeastInput() : \Graphpinator\Typesystem\InputType
103+
{
104+
return new class extends \Graphpinator\Typesystem\InputType {
105+
protected const NAME = 'ConstraintInput';
106+
107+
public function __construct()
108+
{
109+
parent::__construct();
110+
111+
$this->addDirective(
112+
TestSchema::getType('objectConstraint'),
113+
['atLeast' => (object) ['count' => 1, 'from' => ['arg1', 'arg2']]],
114+
);
115+
}
116+
117+
protected function getFieldDefinition() : \Graphpinator\Typesystem\Argument\ArgumentSet
118+
{
119+
return new \Graphpinator\Typesystem\Argument\ArgumentSet([
120+
new \Graphpinator\Typesystem\Argument\Argument(
121+
'arg1',
122+
\Graphpinator\Typesystem\Container::String(),
123+
),
124+
new \Graphpinator\Typesystem\Argument\Argument(
125+
'arg2',
126+
\Graphpinator\Typesystem\Container::String(),
127+
),
128+
]);
129+
}
130+
};
131+
}
132+
133+
private static function getAtMostInput() : \Graphpinator\Typesystem\InputType
134+
{
135+
return new class extends \Graphpinator\Typesystem\InputType {
136+
protected const NAME = 'ConstraintInput';
137+
138+
public function __construct()
139+
{
140+
parent::__construct();
141+
142+
$this->addDirective(
143+
TestSchema::getType('objectConstraint'),
144+
['atMost' => (object) ['count' => 1, 'from' => ['arg1', 'arg2']]],
145+
);
146+
}
147+
148+
protected function getFieldDefinition() : \Graphpinator\Typesystem\Argument\ArgumentSet
149+
{
150+
return new \Graphpinator\Typesystem\Argument\ArgumentSet([
151+
new \Graphpinator\Typesystem\Argument\Argument(
152+
'arg1',
153+
\Graphpinator\Typesystem\Container::String(),
154+
),
155+
new \Graphpinator\Typesystem\Argument\Argument(
156+
'arg2',
157+
\Graphpinator\Typesystem\Container::String(),
158+
),
159+
]);
160+
}
161+
};
162+
}
163+
164+
private static function getExactlyInput() : \Graphpinator\Typesystem\InputType
165+
{
166+
return new class extends \Graphpinator\Typesystem\InputType {
167+
protected const NAME = 'ConstraintInput';
168+
169+
public function __construct()
170+
{
171+
parent::__construct();
172+
173+
$this->addDirective(
174+
TestSchema::getType('objectConstraint'),
175+
['exactly' => (object) ['count' => 1, 'from' => ['arg1', 'arg2']]],
176+
);
177+
}
178+
179+
protected function getFieldDefinition() : \Graphpinator\Typesystem\Argument\ArgumentSet
180+
{
181+
return new \Graphpinator\Typesystem\Argument\ArgumentSet([
182+
new \Graphpinator\Typesystem\Argument\Argument(
183+
'arg1',
184+
\Graphpinator\Typesystem\Container::String(),
185+
),
186+
new \Graphpinator\Typesystem\Argument\Argument(
187+
'arg2',
188+
\Graphpinator\Typesystem\Container::String(),
189+
),
190+
]);
191+
}
192+
};
193+
}
194+
}

tests/Integration/ValidateTypeTest.php renamed to tests/Integration/ValidateUsageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Graphpinator\ConstraintDirectives\Tests\Integration;
66

7-
final class ValidateTypeTest extends \PHPUnit\Framework\TestCase
7+
final class ValidateUsageTest extends \PHPUnit\Framework\TestCase
88
{
99
public function testInvalidConstraintTypeString() : void
1010
{

0 commit comments

Comments
 (0)