Skip to content

Commit 8ccffad

Browse files
committed
Fix test to take care when the table is not on the internal table cache
1 parent a498c6b commit 8ccffad

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

tests/DoctrineTest/UnitTestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ public function fail($message = "")
121121
$this->_fail($message);
122122
}
123123

124+
public function failFromException($e)
125+
{
126+
$this->fail(sprintf('Unexpected exception "%s" %s',
127+
$e->getMessage(),
128+
"\n\n".$e->getTraceAsString()
129+
));
130+
}
131+
124132
public function _fail($message = "")
125133
{
126134
$trace = debug_backtrace();

tests/TableTestCase.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,41 @@ public function testSerialize()
6060

6161
public function testSerializeWithI18nFilter()
6262
{
63-
$table = $this->conn->getTable('I18nFilterTest');
63+
try {
64+
$table = $this->conn->getTable('I18nFilterTest');
6465

65-
$record = $table->create();
66-
$record['name'] = 'foo';
67-
$this->assertEqual('foo', $record['name']);
66+
$record = $table->create();
67+
$record['name'] = 'foo';
68+
$this->assertEqual('foo', $record['name']);
6869

69-
// Test the I18nFilterTest record that include the second filter.
70-
$this->assertTrue(in_array('I18nFilterTestFilter', array_map('get_class', $table->getFilters())));
71-
$expectedFilterNames = array_map('get_class', $table->getFilters());
70+
// Test the I18nFilterTest record that include the second filter.
71+
$this->assertTrue(in_array('I18nFilterTestFilter', array_map('get_class', $table->getFilters())));
72+
$expectedFilterNames = array_map('get_class', $table->getFilters());
7273

73-
$serializedTable = serialize($table);
74+
$serializedTable = serialize($table);
7475

75-
$unserializedTable = unserialize($serializedTable);
76-
$unserializedTable->initializeFromCache($this->conn);
76+
// Remove the table from internal class cache.
77+
$tables = $this->conn->getTables();
78+
$relf = new ReflectionProperty($this->conn, 'tables');
79+
unset($tables['I18nFilterTest']);
80+
unset($tables['I18nFilterTestTranslation']);
81+
$relf->setAccessible(true);
82+
$relf->setValue($this->conn, $tables);
83+
$relf->setAccessible(false);
7784

78-
$record = $unserializedTable->create();
85+
$unserializedTable = unserialize($serializedTable);
86+
$unserializedTable->initializeFromCache($this->conn);
87+
$this->conn->addTable($unserializedTable);
7988

80-
$this->assertEqual($expectedFilterNames, array_map('get_class', $unserializedTable->getFilters()));
89+
$record = $unserializedTable->create();
8190

82-
$record['name'] = 'foo';
83-
$this->assertEqual('foo', $record['name']);
91+
$this->assertEqual($expectedFilterNames, array_map('get_class', $unserializedTable->getFilters()));
92+
93+
$record['name'] = 'foo';
94+
$this->assertEqual('foo', $record['name']);
95+
} catch (Exception $e) {
96+
$this->failFromException($e);
97+
}
8498
}
8599

86100
public function testFieldConversion()

tests/models/I18nFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function postSetUp($event)
3434
}
3535
}
3636

37-
class I18nFilterTestFilter extends Doctrine_Record_Filter
37+
class I18nFilterTestFilter extends Doctrine_Record_Filter_Standard
3838
{
3939
/**
4040
* {@inheritdoc}

0 commit comments

Comments
 (0)