Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 77 lines (65 sloc) 1.943 kB
7c891ae Adding property aliasing
Jonthan Moss authored
1 <?php
2 /**
3 * @author Jonathan Moss <xirisr@gmail.com>
4 * @copyright 2010 Jonathan Moss
5 * @package Morph
6 */
7
8 require_once dirname(__FILE__).'/../Morph.phar';
9 require_once dirname(__FILE__).'/mongoUnit/TestCase.php';
10 require_once dirname(__FILE__).'/test-objects/Aliased.php';
11
12 /**
13 * @package Morph
14 */
15 class TestAliased extends \mongoUnit\TestCase
16 {
17
18 public function setup()
19 {
20 parent::setup();
21 \morph\Storage::init($this->getDatabase());
22 }
23
24 public function tearDown()
25 {
26 parent::tearDown();
27 \morph\Storage::deInit();
28 }
29
30 public function testDataUsesStorageName()
31 {
32 $expected = array(
33 '_ns' => 'Aliased',
34 'n' => 'Chris'
35 );
36 $aliased = new Aliased();
37 $aliased->Name = 'Chris';
38 $this->assertSame($expected, $aliased->__getData());
39 }
40
41 public function testAliasedPropertyIsRestoredCorrectly()
42 {
43 $data = array(
44 '_ns' => 'Aliased',
45 'n' => 'Chris'
46 );
47 $aliased = new Aliased();
48 $aliased->__setData($data);
49 $this->assertSame('Chris', $aliased->Name);
50 }
6c743dd Aliased properties are now dealt with correctly in queries
Jonthan Moss authored
51
52 public function testSearchingAnAliasedProperty()
53 {
54 $aliased = new Aliased();
55 $aliased->Name = 'Chris';
56 $aliased->save();
57
58 $query = \morph\Query::instance()
59 ->property('Name')->equals('Chris');
60
61 $found = \morph\Storage::instance()->findOneByQuery(new Aliased(), $query);
62 $this->assertEquals($aliased->id(), $found->id());
63 }
64
65 public function testSearchAnAliasedPropertyWithItsAlias()
66 {
67 $aliased = new Aliased();
68 $aliased->Name = 'Chris';
69 $aliased->save();
70
71 $query = \morph\Query::instance()
72 ->property('n')->equals('Chris');
73
74 $found = \morph\Storage::instance()->findOneByQuery(new Aliased(), $query);
75 $this->assertEquals($aliased->id(), $found->id());
76 }
7c891ae Adding property aliasing
Jonthan Moss authored
77 }
Something went wrong with that request. Please try again.