forked from lox/pheasant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionScopeTest.php
51 lines (40 loc) · 1.4 KB
/
CollectionScopeTest.php
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
<?php
namespace Pheasant\Tests;
use \Pheasant\Collection;
use \Pheasant\Query\Query;
use \Pheasant\Tests\Examples\Animal;
class CollectionScopeTest extends \Pheasant\Tests\MysqlTestCase
{
public function setUp()
{
parent::setUp();
$migrator = new \Pheasant\Migrate\Migrator();
$migrator
->create('animal', Animal::schema())
;
Animal::import(array(
array('name'=>'Llama', 'type'=>'llama'),
array('name'=>'Blue Frog', 'type'=>'frog'),
array('name'=>'Red Frog', 'type'=>'frog'),
));
}
public function testSimpleScope()
{
$frogs = Animal::all()->frogs();
$this->assertEquals(2, $frogs->count());
}
public function testMultipleFilterCalls(){
$frogs = Animal::all()->filter('id = ?', Animal::all()->last()->id)->frogs();
$this->assertEquals($frogs->one()->name, Animal::all()->last()->name);
}
public function testPassingArgsToScope(){
$frogs_by_type = Animal::all()->filter('id = ?', Animal::all()->last()->id)->by_type('frog');
$frogs = Animal::all()->filter('id = ?', Animal::all()->last()->id)->frogs();
$this->assertEquals($frogs->one()->name, $frogs_by_type->one()->name);
}
public function testNonExistantProperty()
{
$this->setExpectedException('BadMethodCallException');
Animal::all()->llamas();
}
}