This repository was archived by the owner on Dec 10, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +19
-3
lines changed
Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 11language : php
22
33php :
4- - 7.0
54 - 7.1
65 - 7.2
76
Original file line number Diff line number Diff line change 1616 }
1717 ],
1818 "require" : {
19- "php" : " ^7.0 " ,
19+ "php" : " ^7.1 " ,
2020 "illuminate/queue" : " ~5.5.28|~5.6.0" ,
2121 "ramsey/uuid" : " ^3.7"
2222 },
Original file line number Diff line number Diff line change @@ -73,11 +73,19 @@ public static function decodeUuid(string $binaryUuid): string
7373
7474 public function toArray ()
7575 {
76+ if (! $ this ->exists ) {
77+ return parent ::toArray ();
78+ }
79+
7680 return array_merge (parent ::toArray (), [$ this ->getKeyName () => $ this ->uuid_text ]);
7781 }
7882
79- public function getUuidTextAttribute (): string
83+ public function getUuidTextAttribute (): ? string
8084 {
85+ if (! $ this ->exists ) {
86+ return null ;
87+ }
88+
8189 return static ::decodeUuid ($ this ->{$ this ->getKeyName ()});
8290 }
8391
Original file line number Diff line number Diff line change @@ -155,4 +155,13 @@ public function it_serialises_the_model_correctly_with_json_encode()
155155 $ this ->assertContains ($ model ->uuid_text , $ json );
156156 $ this ->assertNotContains ($ model ->uuid , $ json );
157157 }
158+
159+ /** @test */
160+ public function it_prevents_decoding_the_uuid_when_the_model_does_not_exist ()
161+ {
162+ $ model = new TestModel ;
163+
164+ $ this ->assertEmpty ($ model ->toArray ());
165+ $ this ->assertNull ($ model ->uuid_text );
166+ }
158167}
You can’t perform that action at this time.
0 commit comments