Skip to content

Commit de5f350

Browse files
author
Adrian Miu
committed
Changed tests for Sirius\Orm to version 2.0
1 parent 12742a5 commit de5f350

File tree

441 files changed

+28285
-5048
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

441 files changed

+28285
-5048
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ Smaller score is the better (i. e. the faster).
4747

4848
| Library | Insert | Update | Find | Complex| EagerL. | memory usage| time |
4949
| --------------------------------:| ------:| ------:| ------:| ------:| -------:| -----------:| ------:|
50-
| AtlasOrm | 1457 | 1034 | 173 | 181 | 7011 | 7,922,256 | 10.00 |
51-
| CycleOrm | 2369 | 1474 | 278 | 387 | 5810 | 10,000,024 | 10.52 |
52-
| CycleOrmWithGeneratedMapper | 2015 | 1244 | 204 | 386 | 5520 | 12,093,992 | 9.66 |
53-
| CycleOrmDynamicSchema | 2110 | 1680 | 204 | 375 | 4998 | 9,966,568 | 9.49 |
54-
| DoctrineM | 833 | 513 | 505 | 248 | 7203 | 12,582,912 | 9.64 |
55-
| DoctrineMWithCache | 882 | 500 | 547 | 216 | 5827 | 12,582,912 | 8.18 |
56-
| Eloquent | 3106 | 2254 | 456 | 610 | 8552 | 4,194,304 | 15.14 |
57-
| EloquentWithoutEvent | 2841 | 2009 | 456 | 617 | 8073 | 4,194,304 | 14.12 |
58-
| SiriusOrm | 1552 | 1371 | 280 | 234 | 5033 | 3,726,048 | 8.58 |
50+
| AtlasOrm | 1432 | 981 | 176 | 184 | 6903 | 7,922,224 | 9.76 |
51+
| CycleOrm | 2221 | 1454 | 271 | 367 | 5624 | 9,999,992 | 10.07 |
52+
| CycleOrmWithGeneratedMapper | 1901 | 1176 | 213 | 382 | 4422 | 12,093,960 | 8.37 |
53+
| CycleOrmDynamicSchema | 1848 | 1279 | 195 | 346 | 4682 | 9,966,536 | 8.47 |
54+
| DoctrineM | 817 | 472 | 521 | 214 | 6732 | 12,582,912 | 8.97 |
55+
| DoctrineMWithCache | 833 | 479 | 500 | 208 | 7197 | 12,582,912 | 9.43 |
56+
| Eloquent | 3064 | 2185 | 446 | 619 | 8436 | 4,194,304 | 14.87 |
57+
| EloquentWithoutEvent | 2767 | 1897 | 402 | 596 | 7756 | 4,194,304 | 13.52 |
58+
| SiriusOrm | 1742 | 1982 | 335 | 212 | 6040 | 5,818,216 | 10.51 |
59+
5960

6061

6162

siriusorm/SiriusOrmTestSuite.php

Lines changed: 68 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
use Sirius\Orm\Connection;
55
use Sirius\Orm\ConnectionLocator;
6-
use Sirius\Orm\Mapper;
7-
use Sirius\Orm\MapperConfig;
86
use Sirius\Orm\Orm;
9-
use Sirius\Orm\Relation\RelationConfig;
107

118
require_once __DIR__ . '/../AbstractTestSuite.php';
129

@@ -22,6 +19,11 @@ class SiriusOrmTestSuite extends AbstractTestSuite
2219
*/
2320
private $orm;
2421

22+
/**
23+
* @var \app\Entity\Product
24+
*/
25+
private $product;
26+
2527
function initialize()
2628
{
2729
$loader = require_once __DIR__ . "/vendor/autoload.php";
@@ -31,44 +33,21 @@ function initialize()
3133

3234
$this->initTables();
3335

34-
$this->orm->register('products', Mapper::make($this->orm, MapperConfig::fromArray([
35-
MapperConfig::TABLE => 'products',
36-
MapperConfig::COLUMNS => ['id', 'name', 'sku', 'price', 'category_id'],
37-
MapperConfig::RELATIONS => [
38-
'images' => [
39-
RelationConfig::FOREIGN_MAPPER => 'images',
40-
RelationConfig::TYPE => RelationConfig::TYPE_ONE_TO_MANY,
41-
RelationConfig::FOREIGN_KEY => 'imageable_id',
42-
RelationConfig::FOREIGN_GUARDS => ['imageable_type' => 'products']
43-
],
44-
'category' => [
45-
RelationConfig::FOREIGN_MAPPER => 'categories',
46-
RelationConfig::TYPE => RelationConfig::TYPE_MANY_TO_ONE
47-
],
48-
'tags' => [
49-
RelationConfig::FOREIGN_MAPPER => 'tags',
50-
RelationConfig::TYPE => RelationConfig::TYPE_MANY_TO_MANY
51-
]
52-
]
53-
])));
54-
55-
$this->orm->register('categories', Mapper::make($this->orm, MapperConfig::fromArray([
56-
MapperConfig::TABLE => 'categories',
57-
MapperConfig::COLUMNS => ['id', 'name'],
58-
59-
])));
60-
61-
$this->orm->register('tags', Mapper::make($this->orm, MapperConfig::fromArray([
62-
MapperConfig::TABLE => 'tags',
63-
MapperConfig::COLUMNS => ['id', 'name'],
64-
65-
])));
66-
67-
$this->orm->register('images', Mapper::make($this->orm, MapperConfig::fromArray([
68-
MapperConfig::TABLE => 'images',
69-
MapperConfig::COLUMNS => ['id', 'path', 'imageable_id', 'imageable_type'],
70-
71-
])));
36+
require_once __DIR__ . '/definitions.php';
37+
38+
$orm = $this->orm;
39+
$this->orm->register('products', function ($orm) {
40+
return new app\Mapper\ProductMapper($orm);
41+
});
42+
$this->orm->register('categories', function ($orm) {
43+
return new app\Mapper\CategoryMapper($orm);
44+
});
45+
$this->orm->register('tags', function ($orm) {
46+
return new app\Mapper\TagMapper($orm);
47+
});
48+
$this->orm->register('images', function ($orm) {
49+
return new app\Mapper\ImageMapper($orm);
50+
});
7251
}
7352

7453
function clearCache()
@@ -88,7 +67,8 @@ function commit()
8867

8968
function insert($i)
9069
{
91-
$product = $this->orm->get('products')->newEntity([
70+
$mapper = $this->orm->get('products');
71+
$product = $mapper->newEntity([
9272
'name' => 'Product #' . $i,
9373
'sku' => 'SKU #' . $i,
9474
'price' => sqrt(1000 + $i * 100),
@@ -104,72 +84,79 @@ function insert($i)
10484
]
10585
]);
10686

107-
$this->orm->save('products', $product);
87+
$mapper->save($product, ['category', 'images', 'tags']);
10888

109-
$this->products[] = $product->id;
89+
$this->products[] = $product->getId();
11090

11191
return $product;
11292
}
11393

11494
public function test_insert()
11595
{
96+
$mapper = $this->orm->get('products');
11697
$product = $this->insert(0);
117-
$product = $this->orm->find('products', $product->id);
98+
/** @var \app\Entity\Product $product */
99+
$product = $mapper->find($product->getId());
118100
$this->assertNotNull($product, 'Product not found');
119-
$this->assertNotNull($product->category_id, 'Category was not associated with the product');
120-
$this->assertNotNull($product->images[0]->path, 'Image not present');
121-
$this->assertNotNull($product->tags[0]->name, 'Tag not present');
101+
$this->assertNotNull($product->getCategoryId(), 'Category was not associated with the product');
102+
$this->assertNotNull($product->getImages()->get(0)->getPath(), 'Image not present');
103+
$this->assertNotNull($product->getTags()->get(0)->getName(), 'Tag not present');
122104
}
123105

124106
function prepare_update()
125107
{
108+
$mapper = $this->orm->get('products');
126109
$this->product = $this->insert(0);
127-
$this->product = $this->orm->find('products', 1, ['category', 'images', 'tags']);
110+
$this->product = $mapper->find(1, ['category', 'images', 'tags']);
128111
}
129112

130113
function update($i)
131114
{
132-
$this->product->name = 'New product name ' . $i;
133-
$this->product->category->name = 'New category name ' . $i;
134-
$this->product->images[0]->path = 'new_path_' . $i . '.jpg';
135-
$this->product->tags[0]->name = 'New tag name ' . $i;
136-
$this->orm->save('products', $this->product);
115+
$mapper = $this->orm->get('products');
116+
$this->product->setName('New product name ' . $i);
117+
$this->product->getCategory()->setName('New category name ' . $i);
118+
$this->product->getImages()->get(0)->setPath('new_path_' . $i . '.jpg');
119+
$this->product->getTags()->get(0)->setName('New tag name ' . $i);
120+
$mapper->save($this->product, ['category', 'images', 'tags']);
137121
}
138122

139123
function test_update()
140124
{
141-
142-
$this->product->name = 'New product name';
143-
$this->product->category->name = 'New category name';
144-
$this->product->images[0]->path = 'new_path.jpg';
145-
$this->product->tags[0]->set('name', 'New tag name');
146-
$this->orm->save('products', $this->product);
147-
$product = $this->orm->find('products', 1, ['category', 'tags', 'images']);
148-
149-
$this->assertEquals('New product name', $product->name);
150-
$this->assertEquals('New category name', $product->get('category')->name);
151-
$this->assertEquals('new_path.jpg', $product->images[0]->path);
125+
$mapper = $this->orm->get('products');
126+
$this->product->setName('New product name');
127+
$this->product->getCategory()->setName('New category name');
128+
$this->product->getImages()->get(0)->setPath('new_path.jpg');
129+
$this->product->getTags()->get(0)->setName('New tag name');
130+
$mapper->save($this->product, ['category', 'images', 'tags']);
131+
$product = $mapper->find(1, ['category', 'tags', 'images']);
132+
133+
$this->assertEquals('New product name', $product->getName());
134+
$this->assertEquals('New category name', $product->getCategory()->getName());
135+
$this->assertEquals('new_path.jpg', $product->getImages()->get(0)->getPath());
152136

153137
// order not preserved for some reason
154-
$this->assertEquals('New tag name', $product->tags[1]->name);
155-
$this->assertEquals('Tag #t2_0', $product->tags[0]->name);
138+
$this->assertEquals('New tag name', $product->getTags()->get(1)->getName());
139+
$this->assertEquals('Tag #t2_0', $product->getTags()->get(0)->getName());
156140
}
157141

158142
function find($i)
159143
{
160-
$this->orm->find('products', 1);
144+
$mapper = $this->orm->get('products');
145+
$mapper->find(1);
161146
}
162147

163148
function test_find()
164149
{
165-
$product = $this->orm->find('products', 1);
150+
$mapper = $this->orm->get('products');
151+
$product = $mapper->find(1);
166152
$lastRun = self::NB_TEST - 1;
167-
$this->assertEquals('New product name ' . $lastRun, $product->name); // changed by "update"
153+
$this->assertEquals('New product name ' . $lastRun, $product->getName()); // changed by "update"
168154
}
169155

170156
function complexQuery($i)
171157
{
172-
$this->orm->select('products')
158+
$this->orm->get('products')
159+
->newQuery()
173160
->join('INNER', 'categories', 'categories.id = products.category_id')
174161
->where('products.id', 50, '>')
175162
->where('categories.id', 300, '<')
@@ -178,7 +165,8 @@ function complexQuery($i)
178165

179166
function test_complexQuery()
180167
{
181-
$this->assertEquals(249, $this->orm->select('products')
168+
$this->assertEquals(249, $this->orm->get('products')
169+
->newQuery()
182170
->join('INNER', 'categories', 'categories.id = products.category_id')
183171
->where('products.id', 50, '>')
184172
->where('categories.id', 300, '<')
@@ -187,7 +175,8 @@ function test_complexQuery()
187175

188176
function relations($i)
189177
{
190-
$products = $this->orm->select('products')
178+
$products = $this->orm->get('products')
179+
->newQuery()
191180
->load('category', 'tags', 'images')
192181
->where('price', 50, '>')
193182
->limit(10)
@@ -201,10 +190,10 @@ function test_relations()
201190
{
202191
$product = $this->orm->get('products')->find(1);
203192
$lastRun = self::NB_TEST - 1;
204-
$this->assertEquals('New product name ' . $lastRun, $product->name);
205-
$this->assertEquals('New category name ' . $lastRun, $product->category->name);
206-
$this->assertEquals('new_path_' . $lastRun . '.jpg', $product->images[0]->path);
207-
$this->assertEquals('New tag name ' . $lastRun, $product->tags[1]->name);
208-
$this->assertEquals('Tag #t2_0', $product->tags[0]->name);
193+
$this->assertEquals('New product name ' . $lastRun, $product->getName());
194+
$this->assertEquals('New category name ' . $lastRun, $product->getCategory()->getName());
195+
$this->assertEquals('new_path_' . $lastRun . '.jpg', $product->getImages()->get(0)->getPath());
196+
$this->assertEquals('New tag name ' . $lastRun, $product->getTags()->get(1)->getName());
197+
$this->assertEquals('Tag #t2_0', $product->getTags()->get(0)->getName());
209198
}
210-
}
199+
}

siriusorm/composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"require": {
3-
"siriusphp/orm": "^1.0.0"
3+
"siriusphp/orm": "^2.0.0",
4+
"nette/php-generator": "^3.5"
5+
},
6+
"autoload": {
7+
"psr-4": {
8+
"app\\": "src/"
9+
}
410
}
511
}

0 commit comments

Comments
 (0)