Skip to content
Newer
Older
100644 76 lines (58 sloc) 1.81 KB
bb3db5c Adding integration tests along with MongoDB constraint types for PHPUnit
XirisR authored
1 <?php
2 /**
3 * @author Jonathan Moss <xirisr@gmail.com>
4 * @copyright 2010 Jonathan Moss
30132df git-svn-id: http://mongodb-morph.googlecode.com/svn/trunk@120 406649b…
XirisR authored
5 * @package Morph
bb3db5c Adding integration tests along with MongoDB constraint types for PHPUnit
XirisR authored
6 */
7
2207877 refactoring of integration test
XirisR authored
8 require_once dirname(__FILE__).'/../Morph.phar';
aecbbe8 refactoring integration tests by creating a 'MongoUnit' subproject
XirisR authored
9 require_once dirname(__FILE__).'/MongoUnit/TestCase.php';
b5e4010 updated to run from Phing build script
XirisR authored
10 require_once dirname(__FILE__).'/test-objects/HasOneParent.php';
11 require_once dirname(__FILE__).'/test-objects/Child.php';
bb3db5c Adding integration tests along with MongoDB constraint types for PHPUnit
XirisR authored
12
30132df git-svn-id: http://mongodb-morph.googlecode.com/svn/trunk@120 406649b…
XirisR authored
13 /**
14 * @package Morph
15 */
aecbbe8 refactoring integration tests by creating a 'MongoUnit' subproject
XirisR authored
16 class TestHasOne extends MongoUnit_TestCase
bb3db5c Adding integration tests along with MongoDB constraint types for PHPUnit
XirisR authored
17 {
18
aecbbe8 refactoring integration tests by creating a 'MongoUnit' subproject
XirisR authored
19 public function setup()
bb3db5c Adding integration tests along with MongoDB constraint types for PHPUnit
XirisR authored
20 {
aecbbe8 refactoring integration tests by creating a 'MongoUnit' subproject
XirisR authored
21 parent::setup();
22 Morph_Storage::init($this->getDatabase());
1d1a766 updating integration tests for new Morph_Storage usage pattern
XirisR authored
23 }
24
25 public function tearDown()
26 {
27 parent::tearDown();
28 Morph_Storage::deInit();
bb3db5c Adding integration tests along with MongoDB constraint types for PHPUnit
XirisR authored
29 }
30
31 public function testStoresParentAndChild()
32 {
33 $parent = new HasOneParent();
34 $parent->Name = 'Has One Parent';
35
36 $child = new Child();
37 $child->Name = 'Child';
38
39 $parent->Child = $child;
40
1d1a766 updating integration tests for new Morph_Storage usage pattern
XirisR authored
41 $parent->save();
bb3db5c Adding integration tests along with MongoDB constraint types for PHPUnit
XirisR authored
42 $this->assertCollectionExists('HasOneParent');
43 $this->assertCollectionExists('Child');
44
45 $this->assertDocumentExists('HasOneParent', $parent->id());
46 $this->assertDocumentExists('Child', $child->id());
47
48 }
49
f577bfb you can now save a different object in a HasOne relationship (fixes #1)
Jonathan Moss authored
50 public function testStoresReplacementChild()
51 {
52 $parent = new HasOneParent();
53 $parent->Name = 'Has One Parent';
54
55 $child = new Child();
56 $child->Name = 'Child';
57
58 $parent->Child = $child;
59
60 $parent->save();
61 $this->assertCollectionExists('HasOneParent');
62 $this->assertCollectionExists('Child');
63
64 $this->assertDocumentExists('HasOneParent', $parent->id());
65 $this->assertDocumentExists('Child', $child->id());
66
67 //now for the second child
68 $child2 = new Child();
69 $child2->Name = 'Child2';
70 $parent->Child = $child2;
71 $parent->save();
72 $this->assertDocumentExists('Child', $child2->id());
73
74 }
75
bb3db5c Adding integration tests along with MongoDB constraint types for PHPUnit
XirisR authored
76 }
Something went wrong with that request. Please try again.