Example #1
0
 public function testCollectionsSerialize()
 {
     $this->specify("Collections don't serialize/unserialize as expected", function () {
         $songs = StoreSongs::find();
         expect(is_array($songs))->true();
         foreach ($songs as $song) {
             expect($song->delete())->true();
         }
         $trace = [];
         $song = new Songs();
         $song->artist = "Radiohead";
         $song->name = "Lotus Flower";
         expect($song->save())->true();
         $serialized = serialize($song);
         $song = unserialize($serialized);
         expect($song->artist)->equals("Radiohead");
         expect($song->name)->equals("Lotus Flower");
         expect($song->save())->true();
         $song = Songs::findFirst();
         $serialized = serialize($song);
         $song = unserialize($serialized);
         expect($song->artist)->equals("Radiohead");
         expect($song->name)->equals("Lotus Flower");
         expect($song->save())->true();
         $song = new Songs();
         $song->artist = "Massive Attack";
         $song->name = "Paradise Circus";
         expect($song->save())->true();
         $songs = Songs::find();
         expect($songs)->count(2);
         $serialized = serialize($songs);
         $songs = unserialize($serialized);
         expect($songs)->count(2);
     });
 }
Example #2
0
 /**
  * Tests Collection::findFirst
  *
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2016-03-13
  */
 public function testShouldGetCollectionByUsingFindFirst()
 {
     $this->specify("Collection::findFirst does not return expected result", function () {
         $song = Songs::findFirst();
         expect($song->artist)->equals('Radiohead');
         expect($song->name)->equals('Lotus Flower');
         $song = Songs::findFirst([['artist' => 'Massive Attack']]);
         expect($song->artist)->equals('Massive Attack');
         expect($song->name)->equals('Teardrop');
         $song = Songs::findFirst(['conditions' => ['name' => 'Paradise Circus']]);
         expect($song->artist)->equals('Massive Attack');
         expect($song->name)->equals('Paradise Circus');
         expect(Songs::findFirst([['artist' => 'Lana']]))->false();
         expect(Songs::findFirst(['conditions' => ['artist' => 'Lana']]))->false();
     });
 }