-
-
Save lox/33ab5a91edfaf487acf9 to your computer and use it in GitHub Desktop.
A performance test for Pheasant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Pheasant\Tests; | |
use \Pheasant\Types; | |
class Author extends \Pheasant\DomainObject | |
{ | |
public function properties() | |
{ | |
return array( | |
'id' => new Types\Integer(11, 'primary'), | |
'first_name' => new Types\String(255, 'required'), | |
'last_name' => new Types\String(255, 'required'), | |
'email' => new Types\String(255, 'required'), | |
); | |
} | |
public function relationships() | |
{ | |
return array( | |
'Books' => Book::hasOne('author_id') | |
); | |
} | |
} | |
class Book extends \Pheasant\DomainObject | |
{ | |
public function properties() | |
{ | |
return array( | |
'id' => new Types\Integer(11, 'primary'), | |
'title' => new Types\String(255, 'required'), | |
'isbn' => new Types\String(24), | |
'price' => new Types\Decimal(), | |
'author_id' => new Types\Integer(11), | |
); | |
} | |
public function relationships() | |
{ | |
return array( | |
'Author' => Author::hasOne('id') | |
); | |
} | |
} | |
class PerformanceTest extends \Regreph\TestCase | |
{ | |
public function setUp() | |
{ | |
// initialize a new pheasant | |
$this->pheasant = \Pheasant::setup( | |
'mysql://root@localhost/pheasanttest?charset=utf8' | |
); | |
// wipe sequence pool | |
$this->pheasant->connection() | |
->sequencePool() | |
->initialize() | |
->clear() | |
; | |
$migrator = new \Pheasant\Migrate\Migrator(); | |
$migrator | |
->create('author', Author::schema()) | |
->create('book', Book::schema()) | |
; | |
$this->_createTestObjects(); | |
} | |
public function tearDown() | |
{ | |
$this->pheasant->connection()->execute('DROP TABLE author'); | |
$this->pheasant->connection()->execute('DROP TABLE book'); | |
} | |
private function _createTestObjects() | |
{ | |
for($i=0; $i<10; $i++) { | |
$a = new Author(array( | |
'id' => $i, | |
'first_name' => 'John'.$i, | |
'last_name' => 'Doe'.$i, | |
'email' => "johndoe+$i@example.org" | |
)); | |
$a->save(); | |
$b = new Book(array( | |
'id' => $i, | |
'title' => 'The Joy of Llama Farming; Volume '.$i, | |
'isbn' => 'abcd-edfg-123', | |
'price' => 15.00, | |
'author_id' => $a->id | |
)); | |
$b->save(); | |
} | |
} | |
public function testSavingObjects() | |
{ | |
$a = new Author(array( | |
'id' => 1000, | |
'first_name' => 'John1000', | |
'last_name' => 'Doe1000', | |
'email' => "johndoe+1000@example.org" | |
)); | |
$a->save(); | |
$b = new Book(array( | |
'id' => 1000, | |
'title' => 'The Joy of Llama Farming; Volume 1000', | |
'isbn' => 'abcd-edfg-123', | |
'price' => 15.00, | |
'author_id' => $a->id | |
)); | |
$b->save(); | |
} | |
public function testHydrating() | |
{ | |
foreach(Author::find() as $author) { | |
$email = $author->email; | |
} | |
} | |
public function testPkSearch() | |
{ | |
for($i=1; $i<10; $i++) { | |
$book = Book::oneById($i); | |
$title = $book->title; | |
} | |
} | |
public function testEnumerate() | |
{ | |
foreach(Book::find()->limit(10) as $idx=>$book) | |
$title = $book->title; | |
} | |
public function testSearch() | |
{ | |
for($i=1; $i<=10; $i++) | |
$count = Author::find("id > ? OR (first_name = 'John{$i}' OR last_name = 'Doe{$i}')", $i)->count(); | |
} | |
public function testNPlus1() | |
{ | |
foreach(Book::find()->limit(10) as $idx=>$book) | |
$author = $book->Author; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment