Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit a037c46

Browse files
author
Mateo Mujica
committed
ORM test
1 parent 2c8b0a1 commit a037c46

File tree

2 files changed

+51
-48
lines changed

2 files changed

+51
-48
lines changed

Particle/Apps/Controllers/indexController.php

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public function __construct()
1212
}
1313

1414
public function index()
15+
{
16+
$this->view->show();
17+
}
18+
19+
public function testORM()
1520
{
1621
$personMapper = $this->spot->mapper('Particle\Apps\Entities\Person');
1722
$personMapper->migrate();
@@ -22,10 +27,24 @@ public function index()
2227
$sBirthday = '1995-02-24';
2328
$date = new \DateTime($sBirthday);
2429

25-
/* Retrive all */
26-
$people = $personMapper->all();
27-
$books = $bookMapper->all();
28-
30+
/* Relations (In this case de save the relation )*/
31+
$person = $personMapper->create(['PersonName' => 'Teo Muj Jr',
32+
'PersonMail' => 'mateomu18@gmail.com',
33+
'PersonBirthday' => $date,
34+
'PersonCountry' => 'Uruguay']);
35+
$newBook = $bookMapper->build(['BookTitle' => 'The Book 3',
36+
'BookAuthor' => 'Jon Doe',
37+
'BookDatePublished' => $date,
38+
'BookEdition' => 1,
39+
'PersonId' => $person->PersonId,
40+
]);
41+
$newBook->relation('person', $person);
42+
$bookMapper->save($newBook);
43+
$person->relation('books', $newBook);
44+
$personMapper->save($person, ['relations' => true]);
45+
return array('PersonId' => $person->PersonId, 'FisrtBookId'=> $person->books->first()->BookId);
46+
47+
// $booksP = $person->books;
2948

3049
/* Create enetity (Person) */
3150
// $person = $personMapper->first();
@@ -37,7 +56,6 @@ public function index()
3756
// 'BookEdition' => 1,
3857
// ]);
3958

40-
4159
/* Delete && Update */
4260
// $bookDelete = $bookMapper->first();
4361
// $bookDelete->BookTitle = 'Title Change';
@@ -49,27 +67,6 @@ public function index()
4967
// } elseif (is_numeric($result)) {
5068
// $resultD = 'Delete success';
5169
// }
52-
// $this->view->assign('ResultDelete', $resultD);
53-
54-
55-
/* Relations (In this case de save the relation )*/
56-
// $person = $personMapper->create(['PersonName' => 'Teo Muj Jr',
57-
// 'PersonMail' => 'mateomu18@gmail.com',
58-
// 'PersonBirthday' => $date,
59-
// 'PersonCountry' => 'Uruguay']);
60-
// $newBook = $bookMapper->build(['BookTitle' => 'The Book 3',
61-
// 'BookAuthor' => 'Jon Doe',
62-
// 'BookDatePublished' => $date,
63-
// 'BookEdition' => 1,
64-
// 'PersonId' => $person->PersonId,
65-
// ]);
66-
// $newBook->relation('person', $person);
67-
// $bookMapper->save($newBook);
68-
// $person->relation('books', $newBook);
69-
// $personMapper->save($person, ['relations' => true]);
70-
// $booksP = $person->books;
71-
// $this->view->assign('booksP', $booksP);
72-
7370

7471
/* Events (if personId <= 0 exception)*/
7572
// $person = $personMapper->create(['PersonId' => 0,
@@ -79,11 +76,10 @@ public function index()
7976
// 'PersonCountry' => 'Uruguay']);
8077

8178
/* Custom Mapper */
82-
$owners1stEditionBooks = $personMapper->libros1eraEdicion();
83-
$this->view->assign('owners1stEditionBooks', $owners1stEditionBooks);
79+
// $owners1stEditionBooks = $personMapper->libros1eraEdicion();
8480

85-
$this->view->assign('books', $books);
86-
$this->view->assign('people', $people);
87-
$this->view->show();
81+
/* Retrive all */
82+
// $people = $personMapper->all();
83+
// $books = $bookMapper->all();
8884
}
8985
}

Particle/Apps/phpunit/tests/indexTest.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* @covers Particle\Apps\testingController
99
*/
10-
final class TestingControllerTest extends TestCase
10+
final class testingControllerTest extends TestCase
1111
{
1212
protected $view;
1313

@@ -16,22 +16,29 @@ public function setup()
1616
$this->view = new \Smarty();
1717
}
1818

19-
public function testBootstrapDefault()
19+
// public function testBootstrapDefault()
20+
// {
21+
// try {
22+
// Particle\Core\Bootstrap::run(new Particle\Core\Request('testing/testing'));
23+
// $this->assertTrue(true);
24+
// } catch (\Exception $e) {
25+
// $this->fail('Exception: '.$e->getMessage());
26+
// }
27+
// }
28+
//
29+
// public function testSumar()
30+
// {
31+
// $cSuma = new Particle\Apps\testingController;
32+
//
33+
// $resut = $cSuma->suma(2, 1);
34+
//
35+
// $this->assertEquals(3, $resut);
36+
// }
37+
38+
public function testORM()
2039
{
21-
try {
22-
Particle\Core\Bootstrap::run(new Particle\Core\Request('testing/testing'));
23-
$this->assertTrue(true);
24-
} catch (\Exception $e) {
25-
$this->fail('Exception: '.$e->getMessage());
26-
}
27-
}
28-
29-
public function testSumar()
30-
{
31-
$cSuma = new Particle\Apps\testingController;
32-
33-
$resut = $cSuma->suma(2, 1);
34-
35-
$this->assertEquals(3, $resut);
40+
$objIndexController = new Particle/Apps/Controller/indexController;
41+
$aResult = $objIndexController->testORM();
42+
var_dump($aResult);
3643
}
3744
}

0 commit comments

Comments
 (0)