forked from propelorm/Propel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…added a kind of fix for it.
- Loading branch information
marcj
committed
Feb 25, 2013
1 parent
a511f3c
commit 9019d7a
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
require_once dirname(__FILE__) . '/../../../tools/helpers/bookstore/BookstoreTestBase.php'; | ||
|
||
/** | ||
* Proves the issue described in #613 and the fix for it. | ||
* | ||
* Basically it describes that a standalone Criteria does not | ||
* contain the information which table belongs to which model class. | ||
* We've added with this issue a new method `Propel::buildAllTableMaps` which | ||
* can help. See the description of this method for more information. | ||
* | ||
* @see https://github.com/propelorm/Propel/issues/613 | ||
*/ | ||
class Issue613Test extends BookstoreTestBase | ||
{ | ||
|
||
/** | ||
* Creates a | ||
* | ||
* @return string The file path to the serialized Criteria | ||
*/ | ||
private function getPreparedCriteriaObject() | ||
{ | ||
$tmpFile = sys_get_temp_dir().'propel-test-issue-613-serialized-object.tmp'; | ||
BookPeer::clearRelatedInstancePool(); | ||
$criteria = new Criteria(); | ||
$criteria->addSelectColumn(BookPeer::ID); | ||
$criteria->addSelectColumn(AuthorPeer::LAST_NAME); | ||
$criteria->add(BookPeer::ID, 1); | ||
$criteria->addJoin(BookPeer::AUTHOR_ID, AuthorPeer::ID); | ||
file_put_contents($tmpFile, serialize($criteria)); | ||
return $tmpFile; | ||
} | ||
|
||
private function fireTestUnserialization($pScript) | ||
{ | ||
|
||
$tmpFile = $this->getPreparedCriteriaObject(); | ||
$returnCode = 0; | ||
|
||
$cmd = 'php '.escapeshellcmd(__DIR__.'/'.$pScript) . ' ' . escapeshellarg($tmpFile); | ||
system($cmd, $returnCode); | ||
|
||
unlink($tmpFile); | ||
$this->assertEquals(0, $returnCode, 'The unserialization should work without exception.'); | ||
} | ||
|
||
public function testUnserializeCriteria() | ||
{ | ||
$this->fireTestUnserialization('unserialize_criteria.php'); | ||
$this->fireTestUnserialization('unserialize_criteria_buildAllTableMaps.php'); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* This php file tries to load a serialized Criteria, to unserialize it and make the table to model class relation | ||
* known through `BookPeer::buildTableMap` | ||
*/ | ||
|
||
require dirname(__FILE__) . '/../../../../vendor/autoload.php'; | ||
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../../fixtures/bookstore/build/classes')); | ||
Propel::init(__DIR__ . '/../../../fixtures/bookstore/build/conf/bookstore-conf.php'); | ||
|
||
$phpSerializeString = file_get_contents($argv[1]); | ||
|
||
$criteria = unserialize($phpSerializeString); | ||
BookPeer::buildTableMap(); | ||
|
||
$test = BasePeer::doSelect($criteria); | ||
if ($test->queryString !== 'SELECT book.id, author.last_name FROM `book` INNER JOIN `author` ON (book.author_id=author.id) WHERE book.id=:p1') { | ||
exit(1); | ||
} | ||
|
||
exit(0); //Anything went fine |
22 changes: 22 additions & 0 deletions
22
test/testsuite/misc/Issue613/unserialize_criteria_buildAllTableMaps.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* This php file tries to load a serialized Criteria, to unserialize it and make the table to model class relation | ||
* known through `Propel::buildAllTableMaps` | ||
*/ | ||
|
||
require dirname(__FILE__) . '/../../../../vendor/autoload.php'; | ||
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../../fixtures/bookstore/build/classes')); | ||
Propel::init(__DIR__ . '/../../../fixtures/bookstore/build/conf/bookstore-conf.php'); | ||
|
||
$phpSerializeString = file_get_contents($argv[1]); | ||
|
||
$criteria = unserialize($phpSerializeString); | ||
Propel::buildAllTableMaps(); | ||
|
||
$test = BasePeer::doSelect($criteria); | ||
if ($test->queryString !== 'SELECT book.id, author.last_name FROM `book` INNER JOIN `author` ON (book.author_id=author.id) WHERE book.id=:p1') { | ||
exit(1); | ||
} | ||
|
||
exit(0); //Anything went fine |