2121use CloudCreativity \JsonApi \Object \ResourceIdentifier \ResourceIdentifier ;
2222use CloudCreativity \JsonApi \Object \ResourceIdentifier \ResourceIdentifierCollection ;
2323use CloudCreativity \JsonApi \Object \Relationships \Relationship ;
24- use CloudCreativity \JsonApi \Error \ ErrorObject ;
24+ use CloudCreativity \JsonApi \Validator \ ValidatorTestCase ;
2525
26- class HasManyValidatorTest extends \PHPUnit_Framework_TestCase
26+ class HasManyValidatorTest extends ValidatorTestCase
2727{
2828
2929 const TYPE_A = 'foo ' ;
@@ -58,24 +58,6 @@ protected function setUp()
5858 $ this ->validator ->setTypes ([static ::TYPE_A , static ::TYPE_B ]);
5959 }
6060
61- /**
62- * @return ErrorObject
63- */
64- protected function getError ()
65- {
66- if (1 !== count ($ this ->validator ->getErrors ())) {
67- $ this ->fail ('Did not find a single error. ' );
68- }
69-
70- $ error = current ($ this ->validator ->getErrors ()->getAll ());
71-
72- if (!$ error instanceof ErrorObject) {
73- $ this ->fail ('Not an error object. ' );
74- }
75-
76- return $ error ;
77- }
78-
7961 public function testValid ()
8062 {
8163 $ this ->assertTrue ($ this ->validator ->isValid ($ this ->input ));
@@ -87,7 +69,7 @@ public function testNotValid()
8769 {
8870 $ this ->assertFalse ($ this ->validator ->isValid ([]));
8971
90- $ error = $ this ->getError ();
72+ $ error = $ this ->getError ($ this -> validator );
9173 $ this ->assertEquals (HasManyValidator::ERROR_INVALID_VALUE , $ error ->getCode ());
9274 $ this ->assertEquals (400 , $ error ->getStatus ());
9375 }
@@ -97,7 +79,7 @@ public function testBelongsTo()
9779 $ this ->input ->{Relationship::DATA } = null ;
9880 $ this ->assertFalse ($ this ->validator ->isValid ($ this ->input ));
9981
100- $ error = $ this ->getError ();
82+ $ error = $ this ->getError ($ this -> validator );
10183 $ this ->assertEquals (HasManyValidator::ERROR_INVALID_VALUE , $ error ->getCode ());
10284 $ this ->assertEquals (400 , $ error ->getStatus ());
10385 $ this ->assertEquals ('/data ' , $ error ->source ()->getPointer ());
@@ -108,7 +90,7 @@ public function testInvalidType()
10890 $ this ->validator ->setTypes (static ::TYPE_A );
10991 $ this ->assertFalse ($ this ->validator ->isValid ($ this ->input ));
11092
111- $ error = $ this ->getError ();
93+ $ error = $ this ->getError ($ this -> validator );
11294 $ this ->assertEquals (HasManyValidator::ERROR_INVALID_TYPE , $ error ->getCode ());
11395 $ this ->assertEquals (400 , $ error ->getStatus ());
11496 $ this ->assertEquals ('/data/1/type ' , $ error ->source ()->getPointer ());
@@ -119,7 +101,7 @@ public function testMissingType()
119101 unset($ this ->b ->{ResourceIdentifier::TYPE });
120102
121103 $ this ->assertFalse ($ this ->validator ->isValid ($ this ->input ));
122- $ error = $ this ->getError ();
104+ $ error = $ this ->getError ($ this -> validator );
123105 $ this ->assertEquals (HasManyValidator::ERROR_INCOMPLETE_IDENTIFIER , $ error ->getCode ());
124106 $ this ->assertEquals (400 , $ error ->getStatus ());
125107 $ this ->assertEquals ('/data/1 ' , $ error ->source ()->getPointer ());
@@ -130,7 +112,7 @@ public function testInvalidId()
130112 $ this ->b ->{ResourceIdentifier::ID } = null ;
131113 $ this ->assertFalse ($ this ->validator ->isValid ($ this ->input ));
132114
133- $ error = $ this ->getError ();
115+ $ error = $ this ->getError ($ this -> validator );
134116 $ this ->assertEquals (HasManyValidator::ERROR_INVALID_ID , $ error ->getCode ());
135117 $ this ->assertEquals (400 , $ error ->getStatus ());
136118 $ this ->assertEquals ('/data/1/id ' , $ error ->source ()->getPointer ());
@@ -142,7 +124,7 @@ public function testMissingId()
142124 unset($ this ->b ->{ResourceIdentifier::ID });
143125
144126 $ this ->assertFalse ($ this ->validator ->isValid ($ this ->input ));
145- $ error = $ this ->getError ();
127+ $ error = $ this ->getError ($ this -> validator );
146128 $ this ->assertEquals (HasManyValidator::ERROR_INCOMPLETE_IDENTIFIER , $ error ->getCode ());
147129 $ this ->assertEquals (400 , $ error ->getStatus ());
148130 $ this ->assertEquals ('/data/1 ' , $ error ->source ()->getPointer ());
@@ -154,7 +136,7 @@ public function testEmptyNotAcceptable()
154136 $ this ->assertSame ($ this ->validator , $ this ->validator ->setAllowEmpty (false ));
155137 $ this ->assertFalse ($ this ->validator ->isValid ($ this ->input ));
156138
157- $ error = $ this ->getError ();
139+ $ error = $ this ->getError ($ this -> validator );
158140 $ this ->assertEquals (HasManyValidator::ERROR_EMPTY_DISALLOWED , $ error ->getCode ());
159141 $ this ->assertEquals (422 , $ error ->getStatus ());
160142 $ this ->assertEquals ('/data ' , $ error ->source ()->getPointer ());
@@ -190,7 +172,7 @@ public function testCallbackInvalid()
190172
191173 $ this ->assertFalse ($ this ->validator ->isValid ($ this ->input ));
192174
193- $ error = $ this ->getError ();
175+ $ error = $ this ->getError ($ this -> validator );
194176 $ this ->assertEquals (HasManyValidator::ERROR_INVALID_COLLECTION , $ error ->getCode ());
195177 $ this ->assertEquals (400 , $ error ->getStatus ());
196178 $ this ->assertEquals ('/data ' , $ error ->source ()->getPointer ());
@@ -207,7 +189,7 @@ public function testCallbackInvalidIndexes()
207189
208190 $ this ->assertFalse ($ this ->validator ->isValid ($ this ->input ));
209191
210- $ error = $ this ->getError ();
192+ $ error = $ this ->getError ($ this -> validator );
211193 $ this ->assertEquals (HasManyValidator::ERROR_NOT_FOUND , $ error ->getCode ());
212194 $ this ->assertEquals (404 , $ error ->getStatus ());
213195 $ this ->assertEquals ('/data/1 ' , $ error ->source ()->getPointer ());
0 commit comments