diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000000..22f8ecfa4a --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,4 @@ +service_name: travis-ci +src_dir: src +json_path: tests/coveralls.json +coverage_clover: tests/clover.xml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 480eb0335a..efa8048b1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,10 @@ php: - hhvm env: - - DB=mysql DB_USER=root - - DB=pgsql - - DB=sqlite + - DB=agnostic #only database agnostic tests + - DB=mysql DB_USER=root #only database tests against mysql + - DB=pgsql DB_USER=postgres DB_NAME=postgres #only database tests against postgresql +# - DB=sqlite before_script: # Composer @@ -21,8 +22,16 @@ before_script: script: - ./tests/bin/phpunit.$DB.sh; + matrix: fast_finish: true allow_failures: - php: hhvm - php: 5.6 + +after_script: + - php vendor/bin/coveralls -v + +#matrix: +# allow_failures: +# - php: hhvm diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e3165e2e54..7bf265320e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,27 +9,41 @@ stopOnFailure="false" syntaxCheck="false" bootstrap="tests/bootstrap.php" - > +> - - - ./tests/Propel/Tests/ - - + + + ./tests/Propel/Tests/ + + - - - ./src/Propel/ - - ./bin - ./documentation - ./features - ./resources - ./src/Propel/Generator/Behavior/*/templates/ - ./tests - ./tools - ./vendor - - - + + + + + + + ../../src/Propel/ + + ../../src/Propel/Generator/Builder/SQL/Mssql + ../../src/Propel/Generator/Builder/SQL/Oracle + ../../src/Propel/Generator/Builder/SQL/Sqlsrv + + ../../src/Propel/Generator/Platform/MssqlPlatform.php + ../../src/Propel/Generator/Platform/OraclePlatform.php + ../../src/Propel/Generator/Platform/SqlsrvPlatform.php + + ../../src/Propel/Generator/Reverse/MssqlSchemaParser.php + ../../src/Propel/Generator/Reverse/OracleSchemaParser.php + ../../src/Propel/Generator/Reverse/SqlsrvSchemaParser.php + + ../../src/Propel/Runtime/Adapter/MSSQL + ../../src/Propel/Runtime/Adapter/Pdo/MssqlAdapter.php + ../../src/Propel/Runtime/Adapter/Pdo/OracleAdapter.php + ../../src/Propel/Runtime/Adapter/Pdo/SqlsrvAdapter.php + + ../../src/Propel/Runtime/Adapter/Pdo/SqlsrvAdapter.php + + + diff --git a/src/Propel/Generator/Command/MigrationUpCommand.php b/src/Propel/Generator/Command/MigrationUpCommand.php index b9e55024bc..bbe645c7cb 100644 --- a/src/Propel/Generator/Command/MigrationUpCommand.php +++ b/src/Propel/Generator/Command/MigrationUpCommand.php @@ -103,6 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $conn = $manager->getAdapterConnection($datasource); $res = 0; $statements = SqlParser::parseString($sql); + $conn->beginTransaction(); foreach ($statements as $statement) { try { if ($input->getOption('verbose')) { @@ -116,6 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new RuntimeException(sprintf('Failed to execute SQL "%s". Aborting migration.', $statement), 0, $e); } } + $conn->commit(); if (!$res) { $output->writeln('No statement was executed. The version was not updated.'); $output->writeln(sprintf( diff --git a/src/Propel/Generator/Command/TestPrepareCommand.php b/src/Propel/Generator/Command/TestPrepareCommand.php index 4b2585bfdb..efe97ba9e4 100644 --- a/src/Propel/Generator/Command/TestPrepareCommand.php +++ b/src/Propel/Generator/Command/TestPrepareCommand.php @@ -82,6 +82,7 @@ protected function configure() new InputOption('dsn', null, InputOption::VALUE_OPTIONAL, 'The data source name', self::DEFAULT_DSN), new InputOption('user', 'u', InputOption::VALUE_REQUIRED, 'The database user', self::DEFAULT_DB_USER), new InputOption('password', 'p', InputOption::VALUE_REQUIRED, 'The database password', self::DEFAULT_DB_PASSWD), + new InputOption('exclude-schema', null, InputOption::VALUE_NONE, 'Whether this should not touch database\'s schema'), )) ->setName('test:prepare') ->setDescription('Prepare the Propel test suite by building fixtures') @@ -106,15 +107,28 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function buildFixtures($fixturesDir, $connections, InputInterface $input, OutputInterface $output) { - if (!file_exists($fixturesDir)) { + if (!file_exists($this->root . '/' . $fixturesDir)) { $output->writeln(sprintf('Directory "%s" not found.', $fixturesDir)); - return; + return 1; } - $output->writeln(sprintf('Building fixtures in %-40s ', $fixturesDir)); + $output->writeln(sprintf('Building fixtures in %-40s ' . ($input->getOption('exclude-schema') ? '(exclude-schema)' : ''), $fixturesDir)); - chdir($fixturesDir); + chdir($this->root . '/' . $fixturesDir); + + if (0 < count((array) $this->getSchemas('.'))) { + $in = new ArrayInput(array( + 'command' => 'model:build', + '--input-dir' => '.', + '--output-dir' => 'build/classes/', + '--platform' => ucfirst($input->getOption('vendor')) . 'Platform', + '--verbose' => $input->getOption('verbose'), + )); + + $command = $this->getApplication()->find('model:build'); + $command->run($in, $output); + } $distributionFiles = array( 'runtime-conf.xml.dist' => 'runtime-conf.xml', @@ -136,6 +150,22 @@ protected function buildFixtures($fixturesDir, $connections, InputInterface $inp } } + if (is_file('runtime-conf.xml')) { + $in = new ArrayInput(array( + 'command' => 'config:convert-xml', + '--input-dir' => '.', + '--output-dir' => './build/conf', + '--output-file' => sprintf('%s-conf.php', $connections[0]), // the first connection is the main one + )); + + $command = $this->getApplication()->find('config:convert-xml'); + $command->run($in, $output); + } + + if ($input->getOption('exclude-schema')) { + return 0; + } + if (0 < count($this->getSchemas('.'))) { $in = new ArrayInput(array( 'command' => 'sql:build', @@ -176,31 +206,6 @@ protected function buildFixtures($fixturesDir, $connections, InputInterface $inp $command->run($in, $output); } - if (is_file('runtime-conf.xml')) { - $in = new ArrayInput(array( - 'command' => 'config:convert-xml', - '--input-dir' => '.', - '--output-dir' => './build/conf', - '--output-file' => sprintf('%s-conf.php', $connections[0]), // the first connection is the main one - )); - - $command = $this->getApplication()->find('config:convert-xml'); - $command->run($in, $output); - } - - if (0 < count((array) $this->getSchemas('.'))) { - $in = new ArrayInput(array( - 'command' => 'model:build', - '--input-dir' => '.', - '--output-dir' => 'build/classes/', - '--platform' => ucfirst($input->getOption('vendor')) . 'Platform', - '--verbose' => $input->getOption('verbose'), - )); - - $command = $this->getApplication()->find('model:build'); - $command->run($in, $output); - } - chdir($this->root); } } diff --git a/src/Propel/Generator/Manager/MigrationManager.php b/src/Propel/Generator/Manager/MigrationManager.php index 00b8e5ab6f..587469a60a 100644 --- a/src/Propel/Generator/Manager/MigrationManager.php +++ b/src/Propel/Generator/Manager/MigrationManager.php @@ -71,6 +71,10 @@ public function getConnection($datasource) return $this->connections[$datasource]; } + /** + * @param $datasource + * @return ConnectionInterface + */ public function getAdapterConnection($datasource) { if (!isset($this->adapterConnections[$datasource])) { diff --git a/src/Propel/Generator/Platform/SqlitePlatform.php b/src/Propel/Generator/Platform/SqlitePlatform.php index 022f9311d3..404bdfc6e5 100644 --- a/src/Propel/Generator/Platform/SqlitePlatform.php +++ b/src/Propel/Generator/Platform/SqlitePlatform.php @@ -233,7 +233,6 @@ public function getMigrationTableDDL(TableDiff $tableDiff) public function getBeginDDL() { return ' -END; PRAGMA foreign_keys = OFF; '; } @@ -242,7 +241,6 @@ public function getEndDDL() { return ' PRAGMA foreign_keys = ON; -BEGIN; '; } diff --git a/tests/Propel/Tests/BookstoreTest.php b/tests/Propel/Tests/BookstoreTest.php index b6a9c8e0c9..3e0454174a 100644 --- a/tests/Propel/Tests/BookstoreTest.php +++ b/tests/Propel/Tests/BookstoreTest.php @@ -39,6 +39,8 @@ * * @author Francois Zaninotto * @author Hans Lellelid + * + * @group database */ class BookstoreTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/CharacterEncodingTest.php b/tests/Propel/Tests/CharacterEncodingTest.php index faa7abd005..0ca88ff090 100644 --- a/tests/Propel/Tests/CharacterEncodingTest.php +++ b/tests/Propel/Tests/CharacterEncodingTest.php @@ -36,6 +36,8 @@ * * @see BookstoreDataPopulator * @author Hans Lellelid + * + * @group database */ class CharacterEncodingTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/FieldnameRelatedTest.php b/tests/Propel/Tests/FieldnameRelatedTest.php index cfbc990cfb..551a77264d 100644 --- a/tests/Propel/Tests/FieldnameRelatedTest.php +++ b/tests/Propel/Tests/FieldnameRelatedTest.php @@ -33,7 +33,7 @@ * * @author Sven Fuchs */ -class FieldnameRelatedTest extends TestCase +class FieldnameRelatedTest extends TestCaseFixtures { /** * Tests if fieldname type constants are defined diff --git a/tests/Propel/Tests/Generator/Behavior/AddClass/AddClassBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/AddClass/AddClassBehaviorTest.php index c6ad66a822..42494b1158 100644 --- a/tests/Propel/Tests/Generator/Behavior/AddClass/AddClassBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/AddClass/AddClassBehaviorTest.php @@ -10,15 +10,15 @@ namespace Propel\Tests\Generator\Behavior\AddClass; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Behavior\AddClassTableFooClass; +use Propel\Tests\TestCaseFixtures; /** * Tests the generated classes by behaviors. * * @author Francois Zaninotto */ -class AddClassBehaviorTest extends BookstoreTestBase +class AddClassBehaviorTest extends TestCaseFixtures { public function testClassExists() { diff --git a/tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorTest.php index 3e979ba395..95cc4b2375 100644 --- a/tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorTest.php @@ -28,6 +28,8 @@ * Tests for AggregateColumnBehavior class * * @author François Zaninotto + * + * @group database */ class AggregateColumnBehaviorTest extends BookstoreTestBase { @@ -37,7 +39,6 @@ protected function setUp() include_once(__DIR__.'/AggregateColumnsBehaviorTestClasses.php'); } - public function testParameters() { $postTable = AggregatePostTableMap::getTableMap(); diff --git a/tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorWithSchemaTest.php b/tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorWithSchemaTest.php index 67bc91c5ff..f919e830c0 100644 --- a/tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorWithSchemaTest.php +++ b/tests/Propel/Tests/Generator/Behavior/AggregateColumn/AggregateColumnBehaviorWithSchemaTest.php @@ -19,31 +19,19 @@ use Propel\Tests\BookstoreSchemas\Map\BookstoreTableMap; use Propel\Tests\BookstoreSchemas\Customer; use Propel\Tests\BookstoreSchemas\CustomerQuery; -use Propel\Tests\Helpers\Schemas\SchemasTestBase; use Propel\Runtime\Propel; +use Propel\Tests\TestCaseFixturesDatabase; /** * Tests for AggregateColumnBehavior class * * @author François Zaninotto + * + * @group database */ -class AggregateColumnBehaviorWithSchemaTest extends SchemasTestBase +class AggregateColumnBehaviorWithSchemaTest extends TestCaseFixturesDatabase { - protected function setUp() - { - parent::setUp(); - - $this->con = Propel::getServiceContainer()->getConnection(BookstoreTableMap::DATABASE_NAME); - $this->con->beginTransaction(); - } - - protected function tearDown() - { - $this->con->commit(); - parent::tearDown(); - } - public function testParametersWithSchema() { $storeTable = BookstoreTableMap::getTableMap(); @@ -53,41 +41,43 @@ public function testParametersWithSchema() public function testComputeWithSchema() { - BookstoreContestEntryQuery::create()->deleteAll($this->con); - BookstoreQuery::create()->deleteAll($this->con); - CustomerQuery::create()->deleteAll($this->con); - BookstoreContestQuery::create()->deleteAll($this->con); + $con = Propel::getServiceContainer()->getConnection(BookstoreTableMap::DATABASE_NAME); + + BookstoreContestEntryQuery::create()->deleteAll(); + BookstoreQuery::create()->deleteAll(); + CustomerQuery::create()->deleteAll(); + BookstoreContestQuery::create()->deleteAll(); $store = new Bookstore(); $store->setStoreName('FreeAgent Bookstore'); - $store->save($this->con); - $this->assertEquals(0, $store->computeTotalContestEntries($this->con), 'The compute method returns 0 for objects with no related objects'); + $store->save(); + $this->assertEquals(0, $store->computeTotalContestEntries($con), 'The compute method returns 0 for objects with no related objects'); $contest = new BookstoreContest(); $contest->setBookstore($store); - $contest->save($this->con); + $contest->save(); $customer1 = new Customer(); - $customer1->save($this->con); + $customer1->save(); $entry1 = new BookstoreContestEntry(); $entry1->setBookstore($store); $entry1->setBookstoreContest($contest); $entry1->setCustomer($customer1); - $entry1->save($this->con, true); // skip reload to avoid #1151 for now + $entry1->save(null, true); // skip reload to avoid #1151 for now - $this->assertEquals(1, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects'); + $this->assertEquals(1, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects'); $customer2 = new Customer(); - $customer2->save($this->con); + $customer2->save(); $entry2 = new BookstoreContestEntry(); $entry2->setBookstore($store); $entry2->setBookstoreContest($contest); $entry2->setCustomer($customer2); - $entry2->save($this->con, true); // skip reload to avoid #1151 for now + $entry2->save(null, true); // skip reload to avoid #1151 for now - $this->assertEquals(2, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects'); - $entry1->delete($this->con); - $this->assertEquals(1, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects'); + $this->assertEquals(2, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects'); + $entry1->delete(); + $this->assertEquals(1, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects'); } } diff --git a/tests/Propel/Tests/Generator/Behavior/AutoAddPk/AutoAddPkBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/AutoAddPk/AutoAddPkBehaviorTest.php index 79c71369fa..210a19ce91 100644 --- a/tests/Propel/Tests/Generator/Behavior/AutoAddPk/AutoAddPkBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/AutoAddPk/AutoAddPkBehaviorTest.php @@ -23,8 +23,8 @@ * Tests for AutoAddPkBehavior class * * @author François Zaninotto - * @version $Revision$ - * @package generator.behavior + * + * @group database */ class AutoAddPkBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehaviorTest.php index 9d7397a892..3f46aa93d9 100644 --- a/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehaviorTest.php @@ -35,6 +35,8 @@ * Tests for ConcreteInheritanceBehavior class * * @author François Zaniontto + * + * @group database */ class ConcreteInheritanceBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehaviorWithSchemaTest.php b/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehaviorWithSchemaTest.php index 3bff9481da..e2bdab2072 100644 --- a/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehaviorWithSchemaTest.php +++ b/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehaviorWithSchemaTest.php @@ -14,15 +14,16 @@ use Propel\Tests\BookstoreSchemas\Book; use Propel\Tests\BookstoreSchemas\SecondHandBook; use Propel\Tests\BookstoreSchemas\Map\BookTableMap; -use Propel\Tests\Helpers\Schemas\SchemasTestBase; +use Propel\Tests\TestCaseFixturesDatabase; /** * Tests for ConcreteInheritanceBehavior class * * @author François Zaniontto - * @version $Revision$ + * + * @group database */ -class ConcreteInheritanceBehaviorWithSchemaTest extends SchemasTestBase +class ConcreteInheritanceBehaviorWithSchemaTest extends TestCaseFixturesDatabase { public function testParentBehaviorWithSchemas() { diff --git a/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceParentBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceParentBehaviorTest.php index 08a9c2a3b9..bb7b7eacc3 100644 --- a/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceParentBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceParentBehaviorTest.php @@ -23,7 +23,8 @@ * Tests for ConcreteInheritanceParentBehavior class * * @author François Zaniontto - * @version $Revision$ + * + * @group database */ class ConcreteInheritanceParentBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/I18n/I18nBehaviorQueryBuilderModifierTest.php b/tests/Propel/Tests/Generator/Behavior/I18n/I18nBehaviorQueryBuilderModifierTest.php index da6ff5881e..7b635adb07 100644 --- a/tests/Propel/Tests/Generator/Behavior/I18n/I18nBehaviorQueryBuilderModifierTest.php +++ b/tests/Propel/Tests/Generator/Behavior/I18n/I18nBehaviorQueryBuilderModifierTest.php @@ -23,10 +23,6 @@ */ class I18nBehaviorQueryBuilderModifierTest extends TestCase { - protected function getDriver() - { - return 'sqlite'; - } public function setUp() { diff --git a/tests/Propel/Tests/Generator/Behavior/ObjectBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/ObjectBehaviorTest.php index d72312742a..63ef21c3d7 100644 --- a/tests/Propel/Tests/Generator/Behavior/ObjectBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/ObjectBehaviorTest.php @@ -17,6 +17,8 @@ * Tests the generated Object behavior hooks. * * @author Francois Zaninotto + * + * @group database */ class ObjectBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/QueryBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/QueryBehaviorTest.php index 980f37ed9c..d8a64dc52d 100644 --- a/tests/Propel/Tests/Generator/Behavior/QueryBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/QueryBehaviorTest.php @@ -18,6 +18,8 @@ * Tests the generated query behavior hooks. * * @author Francois Zaninotto + * + * @group database */ class QueryBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/QueryCache/QueryCacheTest.php b/tests/Propel/Tests/Generator/Behavior/QueryCache/QueryCacheTest.php index 310df8858f..ac5c9c5aa8 100644 --- a/tests/Propel/Tests/Generator/Behavior/QueryCache/QueryCacheTest.php +++ b/tests/Propel/Tests/Generator/Behavior/QueryCache/QueryCacheTest.php @@ -15,7 +15,10 @@ /** * Class QueryCacheTest + * * @author Manuel Raynaud + * + * @group database */ class QueryCacheTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sluggable/SluggableBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/Sluggable/SluggableBehaviorTest.php index a7d7bf86cc..dc1b84c84b 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sluggable/SluggableBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Sluggable/SluggableBehaviorTest.php @@ -23,12 +23,13 @@ use Propel\Tests\Bookstore\Behavior\Map\Table14TableMap; use Propel\Tests\Bookstore\Behavior\TableWithScope; use Propel\Tests\Bookstore\Behavior\TableWithScopeQuery; -use Propel\Tests\TestCase; /** * Tests for SluggableBehavior class * * @author François Zaninotto + * + * @group database */ class SluggableBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorObjectBuilderModifierTest.php b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorObjectBuilderModifierTest.php index 58a6762862..c4e8ee7c91 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorObjectBuilderModifierTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorObjectBuilderModifierTest.php @@ -18,6 +18,8 @@ * Tests for SortableBehavior class * * @author Massimiliano Arione + * + * @group database */ class SortableBehaviorObjectBuilderModifierTest extends TestCase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorObjectBuilderModifierWithScopeTest.php b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorObjectBuilderModifierWithScopeTest.php index a30326e4e3..a057124286 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorObjectBuilderModifierWithScopeTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorObjectBuilderModifierWithScopeTest.php @@ -23,6 +23,8 @@ * Tests for SortableBehavior class * * @author Massimiliano Arione + * + * @group database */ class SortableBehaviorObjectBuilderModifierWithScopeTest extends TestCase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifierTest.php b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifierTest.php index f24f9e0af9..88ad9eb0c6 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifierTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifierTest.php @@ -21,6 +21,8 @@ * Tests for SortableBehavior class query modifier * * @author Francois Zaninotto + * + * @group database */ class SortableBehaviorQueryBuilderModifierTest extends TestCase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifierWithScopeTest.php b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifierWithScopeTest.php index 366d1e6511..40a87b0ea5 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifierWithScopeTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryBuilderModifierWithScopeTest.php @@ -21,6 +21,8 @@ * Tests for SortableBehavior class query modifier when the scope is enabled * * @author Francois Zaninotto + * + * @group database */ class SortableBehaviorQueryBuilderModifierWithScopeTest extends TestCase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryUtilsBuilderModifierTest.php b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryUtilsBuilderModifierTest.php index f7e48e962c..14e7351fb8 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryUtilsBuilderModifierTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryUtilsBuilderModifierTest.php @@ -19,6 +19,8 @@ * Tests for SortableBehavior class * * @author Massimiliano Arione + * + * @group database */ class SortableBehaviorQueryUtilsBuilderModifierTest extends TestCase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryUtilsBuilderModifierWithScopeTest.php b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryUtilsBuilderModifierWithScopeTest.php index 6ec1796bab..8ac47772f7 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryUtilsBuilderModifierWithScopeTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorQueryUtilsBuilderModifierWithScopeTest.php @@ -19,6 +19,8 @@ * Tests for SortableBehavior class * * @author Massimiliano Arione + * + * @group database */ class SortableBehaviorQueryUtilsBuilderModifierWithScopeTest extends TestCase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorTest.php index bcf7e161a3..eb9767480a 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Sortable/SortableBehaviorTest.php @@ -18,6 +18,8 @@ * * @author Massimiliano Arione * @author William Durand + * + * @group database */ class SortableBehaviorTest extends TestCase { diff --git a/tests/Propel/Tests/Generator/Behavior/Sortable/TestCase.php b/tests/Propel/Tests/Generator/Behavior/Sortable/TestCase.php index 14fa52fcdf..1cef85c8c1 100644 --- a/tests/Propel/Tests/Generator/Behavior/Sortable/TestCase.php +++ b/tests/Propel/Tests/Generator/Behavior/Sortable/TestCase.php @@ -12,23 +12,19 @@ use Propel\Runtime\ActiveQuery\Criteria; -use Propel\Tests\TestCase as BaseTestCase; use Propel\Tests\Bookstore\Behavior\SortableTable11; use Propel\Tests\Bookstore\Behavior\SortableTable11Query; use Propel\Tests\Bookstore\Behavior\SortableTable12; use Propel\Tests\Bookstore\Behavior\SortableTable12Query; use Propel\Tests\Bookstore\Behavior\Map\SortableTable12TableMap; use Propel\Tests\Bookstore\Behavior\Map\SortableTable11TableMap; +use Propel\Tests\TestCaseFixturesDatabase; /** * @author William Durand */ -class TestCase extends BaseTestCase +class TestCase extends TestCaseFixturesDatabase { - public function setUp() - { - require(__DIR__ . '/../../../../../Fixtures/bookstore/build/conf/bookstore-conf.php'); - } protected function populateTable11() { diff --git a/tests/Propel/Tests/Generator/Behavior/Timestampable/TimestampableBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/Timestampable/TimestampableBehaviorTest.php index 82124fe118..937c97bec9 100644 --- a/tests/Propel/Tests/Generator/Behavior/Timestampable/TimestampableBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Timestampable/TimestampableBehaviorTest.php @@ -25,6 +25,8 @@ * Tests for TimestampableBehavior class * * @author François Zaninotto + * + * @group database */ class TimestampableBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/Validate/I18nConcreteInheritanceHandleValidateBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/Validate/I18nConcreteInheritanceHandleValidateBehaviorTest.php index 971f5de680..e8bbbe27ce 100644 --- a/tests/Propel/Tests/Generator/Behavior/Validate/I18nConcreteInheritanceHandleValidateBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Validate/I18nConcreteInheritanceHandleValidateBehaviorTest.php @@ -19,6 +19,8 @@ * and Validate behavior. * * @author Cristiano Cinotti + * + * @group database */ class I18nConcreteInheritanceHandleValidateBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/Validate/UniqueConstraintTest.php b/tests/Propel/Tests/Generator/Behavior/Validate/UniqueConstraintTest.php index 25478a8e44..d5caaa63ed 100644 --- a/tests/Propel/Tests/Generator/Behavior/Validate/UniqueConstraintTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Validate/UniqueConstraintTest.php @@ -18,6 +18,8 @@ * Tests for Unique Constraint * * @author Cristiano Cinotti + * + * @group database */ class UniqueConstraintTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Behavior/Validate/ValidateBehaviorTest.php b/tests/Propel/Tests/Generator/Behavior/Validate/ValidateBehaviorTest.php index 7285edbd78..286fddfc7c 100755 --- a/tests/Propel/Tests/Generator/Behavior/Validate/ValidateBehaviorTest.php +++ b/tests/Propel/Tests/Generator/Behavior/Validate/ValidateBehaviorTest.php @@ -22,6 +22,8 @@ * Tests for ValidateBehavior class * * @author Cristiano Cinotti + * + * @group database */ class ValidateBehaviorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Builder/NamespaceTest.php b/tests/Propel/Tests/Generator/Builder/NamespaceTest.php index 2430cece7d..4b322f21ae 100644 --- a/tests/Propel/Tests/Generator/Builder/NamespaceTest.php +++ b/tests/Propel/Tests/Generator/Builder/NamespaceTest.php @@ -11,26 +11,27 @@ namespace Propel\Tests\Generator\Builder; use Propel\Runtime\Propel; -use Propel\Tests\TestCase; +use Propel\Tests\TestCaseFixturesDatabase; /** * Tests for Namespaces in generated classes class * Requires a build of the 'namespaced' fixture * + * @group database */ -class NamespaceTest extends TestCase +class NamespaceTest extends TestCaseFixturesDatabase { - protected function setUp() - { - parent::setUp(); - Propel::init(__DIR__ . '/../../../../Fixtures/namespaced/build/conf/bookstore_namespaced-conf.php'); - } - - protected function tearDown() - { - parent::tearDown(); - Propel::init(dirname(__FILE__) . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php'); - } +// protected function setUp() +// { +// parent::setUp(); +// Propel::init(__DIR__ . '/../../../../Fixtures/namespaced/build/conf/bookstore_namespaced-conf.php'); +// } +// +// protected function tearDown() +// { +// parent::tearDown(); +// Propel::init(dirname(__FILE__) . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php'); +// } public function testInsert() { diff --git a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectLobTest.php b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectLobTest.php index 74e4676024..7b76b64128 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectLobTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectLobTest.php @@ -35,6 +35,8 @@ * * @see BookstoreDataPopulator * @author Hans Lellelid + * + * @group database */ class GeneratedObjectLobTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectRelTest.php b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectRelTest.php index f5319ef84f..220b55828f 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectRelTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectRelTest.php @@ -50,6 +50,8 @@ * method for the exact contents of the database. * * @author Hans Lellelid + * + * @group database */ class GeneratedObjectRelTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTest.php b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTest.php index d55e0e631b..3df7c651c8 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTest.php @@ -71,6 +71,8 @@ * method for the exact contents of the database. * * @author Hans Lellelid + * + * @group database */ class GeneratedObjectTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectWithFixturesTest.php b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectWithFixturesTest.php index 645a223964..1a1aba5395 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectWithFixturesTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectWithFixturesTest.php @@ -43,6 +43,8 @@ * * @see BookstoreDataPopulator * @author Hans Lellelid + * + * @group database */ class GeneratedObjectWithFixturesTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Generator/Builder/Om/GeneratedQueryDoDeleteTest.php b/tests/Propel/Tests/Generator/Builder/Om/GeneratedQueryDoDeleteTest.php index f6bbf6600b..d73206cbaa 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/GeneratedQueryDoDeleteTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/GeneratedQueryDoDeleteTest.php @@ -53,6 +53,8 @@ * * @see BookstoreDataPopulator * @author Hans Lellelid + * + * @group database */ class GeneratedQueryDoDeleteTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Generator/Builder/Om/GeneratedTableMapTest.php b/tests/Propel/Tests/Generator/Builder/Om/GeneratedTableMapTest.php index 6531e7e7f6..8587ae9712 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/GeneratedTableMapTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/GeneratedTableMapTest.php @@ -33,6 +33,8 @@ * * @see BookstoreDataPopulator * @author Hans Lellelid + * + * @group database */ class GeneratedTableMapTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Builder/Om/PoisonedCacheBugTest.php b/tests/Propel/Tests/Generator/Builder/Om/PoisonedCacheBugTest.php index fb356af371..3633c266ba 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/PoisonedCacheBugTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/PoisonedCacheBugTest.php @@ -20,6 +20,9 @@ use Propel\Tests\Bookstore\Map\BookTableMap; use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; +/** + * @group database + */ class PoisonedCacheBugTest extends BookstoreTestBase { /** diff --git a/tests/Propel/Tests/Generator/Builder/Om/QueryBuilderInheritanceTest.php b/tests/Propel/Tests/Generator/Builder/Om/QueryBuilderInheritanceTest.php index 995ba57801..d0d2eecdc3 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/QueryBuilderInheritanceTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/QueryBuilderInheritanceTest.php @@ -31,7 +31,8 @@ * Test class for MultiExtensionQueryBuilder. * * @author François Zaninotto - * @version $Id: QueryBuilderTest.php 1347 2009-12-03 21:06:36Z francois $ + * + * @group database */ class QueryBuilderInheritanceTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Generator/Builder/Om/QueryBuilderTest.php b/tests/Propel/Tests/Generator/Builder/Om/QueryBuilderTest.php index 59e47ceb39..4b3541a47a 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/QueryBuilderTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/QueryBuilderTest.php @@ -46,7 +46,8 @@ * Test class for QueryBuilder. * * @author François Zaninotto - * @version $Id: QueryBuilderTest.php 1347 2009-12-03 21:06:36Z francois $ + * + * @group database */ class QueryBuilderTest extends BookstoreTestBase { @@ -1097,4 +1098,4 @@ public function testPruneCompositeKey() $nbBookListRel = BookListRelQuery::create()->prune($testBookListRel)->count(); $this->assertEquals(1, $nbBookListRel, 'prune() removes an object from the result'); } -} \ No newline at end of file +} diff --git a/tests/Propel/Tests/Generator/Builder/Om/TableMapBuilderTest.php b/tests/Propel/Tests/Generator/Builder/Om/TableMapBuilderTest.php index 4b6cd61384..e570520917 100644 --- a/tests/Propel/Tests/Generator/Builder/Om/TableMapBuilderTest.php +++ b/tests/Propel/Tests/Generator/Builder/Om/TableMapBuilderTest.php @@ -19,6 +19,8 @@ * Test class for TableMapBuilder. * * @author François Zaninotto + * + * @group database */ class TableMapBuilderTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Command/DatabaseReverseTest.php b/tests/Propel/Tests/Generator/Command/DatabaseReverseTest.php similarity index 86% rename from tests/Propel/Tests/Command/DatabaseReverseTest.php rename to tests/Propel/Tests/Generator/Command/DatabaseReverseTest.php index e747cadd29..ecd22e8295 100644 --- a/tests/Propel/Tests/Command/DatabaseReverseTest.php +++ b/tests/Propel/Tests/Generator/Command/DatabaseReverseTest.php @@ -1,13 +1,16 @@ add($command); - $outputDir = __DIR__.'/../../../reversecommand'; + $outputDir = __DIR__.'/../../../../reversecommand'; $input = new \Symfony\Component\Console\Input\ArrayInput(array( 'command' => 'database:reverse', @@ -23,7 +26,7 @@ public function testCommand() '--output-dir' => $outputDir, '--verbose' => true, '--platform' => ucfirst($this->getDriver()).'Platform', - 'connection' => $this->getConnectionDsn('bookstore-schemas') + 'connection' => $this->getConnectionDsn('bookstore-schemas', true) )); $output = new \Symfony\Component\Console\Output\BufferedOutput(); diff --git a/tests/Propel/Tests/Command/GraphvizGenerateTest.php b/tests/Propel/Tests/Generator/Command/GraphvizGenerateTest.php similarity index 86% rename from tests/Propel/Tests/Command/GraphvizGenerateTest.php rename to tests/Propel/Tests/Generator/Command/GraphvizGenerateTest.php index aca994c882..6d26ab8094 100644 --- a/tests/Propel/Tests/Command/GraphvizGenerateTest.php +++ b/tests/Propel/Tests/Generator/Command/GraphvizGenerateTest.php @@ -1,6 +1,6 @@ add($command); - $outputDir = __DIR__.'/../../../graphviztest'; + $outputDir = __DIR__.'/../../../../graphviztest'; $input = new \Symfony\Component\Console\Input\ArrayInput(array( 'command' => 'graphviz:generate', - '--input-dir' => __DIR__ . '/../../../Fixtures/bookstore', + '--input-dir' => __DIR__ . '/../../../../Fixtures/bookstore', '--output-dir' => $outputDir, '--verbose' => true )); diff --git a/tests/Propel/Tests/Command/MigrationTest.php b/tests/Propel/Tests/Generator/Command/MigrationTest.php similarity index 94% rename from tests/Propel/Tests/Command/MigrationTest.php rename to tests/Propel/Tests/Generator/Command/MigrationTest.php index 71ff1fb872..88f05f8b96 100644 --- a/tests/Propel/Tests/Command/MigrationTest.php +++ b/tests/Propel/Tests/Generator/Command/MigrationTest.php @@ -1,18 +1,21 @@ connectionOption = ['migration_command=' . $this->getConnectionDsn('bookstore', true)]; $this->connectionOption = str_replace('dbname=test', 'dbname=migration', $this->connectionOption); - $this->inputDir = __DIR__ . '/../../../Fixtures/migration-command'; + $this->inputDir = __DIR__ . '/../../../../Fixtures/migration-command'; $this->outputDir = __DIR__ . self::$output; } diff --git a/tests/Propel/Tests/Generator/Migration/BaseTest.php b/tests/Propel/Tests/Generator/Migration/BaseTest.php index 1a30fe1d67..8426aa8e41 100644 --- a/tests/Propel/Tests/Generator/Migration/BaseTest.php +++ b/tests/Propel/Tests/Generator/Migration/BaseTest.php @@ -2,6 +2,9 @@ namespace Propel\Tests\Generator\Migration; +/** + * @group database + */ class BaseTest extends MigrationTestCase { diff --git a/tests/Propel/Tests/Generator/Migration/ForeignKeyTest.php b/tests/Propel/Tests/Generator/Migration/ForeignKeyTest.php index 2edf9d6a63..9994cbca58 100644 --- a/tests/Propel/Tests/Generator/Migration/ForeignKeyTest.php +++ b/tests/Propel/Tests/Generator/Migration/ForeignKeyTest.php @@ -2,6 +2,9 @@ namespace Propel\Tests\Generator\Migration; +/** + * @group database + */ class ForeignKeyTest extends MigrationTestCase { diff --git a/tests/Propel/Tests/Generator/Migration/IndexTest.php b/tests/Propel/Tests/Generator/Migration/IndexTest.php index 0dcbcb73a3..dcb2d69e3c 100644 --- a/tests/Propel/Tests/Generator/Migration/IndexTest.php +++ b/tests/Propel/Tests/Generator/Migration/IndexTest.php @@ -2,6 +2,9 @@ namespace Propel\Tests\Generator\Migration; +/** + * @group database + */ class IndexTest extends MigrationTestCase { diff --git a/tests/Propel/Tests/Generator/Migration/MigrationTestCase.php b/tests/Propel/Tests/Generator/Migration/MigrationTestCase.php index 0145089f3b..a275ce5960 100644 --- a/tests/Propel/Tests/Generator/Migration/MigrationTestCase.php +++ b/tests/Propel/Tests/Generator/Migration/MigrationTestCase.php @@ -9,9 +9,9 @@ use Propel\Generator\Util\QuickBuilder; use Propel\Generator\Util\SqlParser; use Propel\Runtime\Propel; -use Propel\Tests\TestCase; +use Propel\Tests\TestCaseFixturesDatabase; -class MigrationTestCase extends TestCase +class MigrationTestCase extends TestCaseFixturesDatabase { /** diff --git a/tests/Propel/Tests/Generator/Migration/PrimaryKeyAITest.php b/tests/Propel/Tests/Generator/Migration/PrimaryKeyAITest.php index 53c36b8a32..6eeba1216d 100644 --- a/tests/Propel/Tests/Generator/Migration/PrimaryKeyAITest.php +++ b/tests/Propel/Tests/Generator/Migration/PrimaryKeyAITest.php @@ -2,6 +2,9 @@ namespace Propel\Tests\Generator\Migration; +/** + * @group database + */ class PrimaryKeyAITest extends MigrationTestCase { diff --git a/tests/Propel/Tests/Generator/Migration/PrimaryKeyTest.php b/tests/Propel/Tests/Generator/Migration/PrimaryKeyTest.php index b4b736a1b8..5eb2124f17 100644 --- a/tests/Propel/Tests/Generator/Migration/PrimaryKeyTest.php +++ b/tests/Propel/Tests/Generator/Migration/PrimaryKeyTest.php @@ -2,6 +2,9 @@ namespace Propel\Tests\Generator\Migration; +/** + * @group database + */ class PrimaryKeyTest extends MigrationTestCase { diff --git a/tests/Propel/Tests/Generator/Reverse/MysqlSchemaParserTest.php b/tests/Propel/Tests/Generator/Reverse/MysqlSchemaParserTest.php index 5f320ff8ab..2b411d06d4 100644 --- a/tests/Propel/Tests/Generator/Reverse/MysqlSchemaParserTest.php +++ b/tests/Propel/Tests/Generator/Reverse/MysqlSchemaParserTest.php @@ -16,27 +16,17 @@ use Propel\Generator\Reverse\MysqlSchemaParser; use Propel\Runtime\Propel; -use Propel\Tests\TestCase; +use Propel\Tests\TestCaseFixturesDatabase; /** * Tests for Mysql database schema parser. * * @author William Durand - * @version $Revision$ + * + * @group database */ -class MysqlSchemaParserTest extends TestCase +class MysqlSchemaParserTest extends TestCaseFixturesDatabase { - protected function setUp() - { - parent::setUp(); - Propel::init(__DIR__ . '/../../../../Fixtures/reverse/mysql/build/conf/reverse-bookstore-conf.php'); - } - - protected function tearDown() - { - parent::tearDown(); - Propel::init(__DIR__ . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php'); - } public function testParse() { diff --git a/tests/Propel/Tests/Generator/Reverse/PgsqlSchemaParserTest.php b/tests/Propel/Tests/Generator/Reverse/PgsqlSchemaParserTest.php index 654482e93f..9f212ac493 100644 --- a/tests/Propel/Tests/Generator/Reverse/PgsqlSchemaParserTest.php +++ b/tests/Propel/Tests/Generator/Reverse/PgsqlSchemaParserTest.php @@ -16,15 +16,16 @@ use Propel\Generator\Platform\DefaultPlatform; use Propel\Generator\Reverse\PgsqlSchemaParser; use Propel\Runtime\Propel; -use Propel\Tests\TestCase; +use Propel\Tests\TestCaseFixturesDatabase; /** * Tests for Pgsql database schema parser. * * @author Alan Pinstein * @group pgsql + * @group database */ -class PgsqlSchemaParserTest extends TestCase +class PgsqlSchemaParserTest extends TestCaseFixturesDatabase { protected function setUp() { diff --git a/tests/Propel/Tests/Helpers/Bookstore/BookstoreDataPopulator.php b/tests/Propel/Tests/Helpers/Bookstore/BookstoreDataPopulator.php index b9f4fb9151..1150516e4d 100644 --- a/tests/Propel/Tests/Helpers/Bookstore/BookstoreDataPopulator.php +++ b/tests/Propel/Tests/Helpers/Bookstore/BookstoreDataPopulator.php @@ -310,12 +310,6 @@ public static function depopulate($con = null) } $tableMapClass::doDeleteAll($con); } - // delete records from the database - if ($con === null) { - $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME); - } - $con->beginTransaction(); - $con->commit(); } } diff --git a/tests/Propel/Tests/Helpers/Bookstore/BookstoreEmptyTestBase.php b/tests/Propel/Tests/Helpers/Bookstore/BookstoreEmptyTestBase.php index 8a3f3ea9f6..6e42051a84 100644 --- a/tests/Propel/Tests/Helpers/Bookstore/BookstoreEmptyTestBase.php +++ b/tests/Propel/Tests/Helpers/Bookstore/BookstoreEmptyTestBase.php @@ -21,7 +21,9 @@ abstract class BookstoreEmptyTestBase extends BookstoreTestBase protected function setUp() { parent::setUp(); - BookstoreDataPopulator::depopulate($this->con); + if (static::$isInitialized) { + BookstoreDataPopulator::depopulate($this->con); + } } } diff --git a/tests/Propel/Tests/Helpers/Bookstore/BookstoreTestBase.php b/tests/Propel/Tests/Helpers/Bookstore/BookstoreTestBase.php index 6f40a9eacc..f984184d53 100644 --- a/tests/Propel/Tests/Helpers/Bookstore/BookstoreTestBase.php +++ b/tests/Propel/Tests/Helpers/Bookstore/BookstoreTestBase.php @@ -12,12 +12,12 @@ use Propel\Runtime\Propel; use Propel\Tests\Bookstore\Map\BookTableMap; -use Propel\Tests\TestCase; +use Propel\Tests\TestCaseFixturesDatabase; /** * Base class contains some methods shared by subclass test cases. */ -abstract class BookstoreTestBase extends TestCase +abstract class BookstoreTestBase extends TestCaseFixturesDatabase { /** * @var Boolean @@ -35,6 +35,10 @@ protected function setUp() { parent::setUp(); if (true !== self::$isInitialized) { + $file = __DIR__ . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php'; + if (!file_exists($file)) { + return; + } Propel::init(__DIR__ . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php'); self::$isInitialized = true; } diff --git a/tests/Propel/Tests/Helpers/Schemas/SchemasTestBase.php b/tests/Propel/Tests/Helpers/Schemas/SchemasTestBase.php deleted file mode 100644 index 6661d72f7c..0000000000 --- a/tests/Propel/Tests/Helpers/Schemas/SchemasTestBase.php +++ /dev/null @@ -1,44 +0,0 @@ -markTestSkipped('You must build the schemas project for this tests to run'); - } - } - - protected function tearDown() - { - } - - public static function tearDownAfterClass() - { - Propel::getServiceContainer()->closeConnections(); - Propel::init(dirname(__FILE__) . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php'); - } -} diff --git a/tests/Propel/Tests/Issues/Issue617Test.php b/tests/Propel/Tests/Issues/Issue617Test.php index 48d788a9cf..69bbb3c1f4 100644 --- a/tests/Propel/Tests/Issues/Issue617Test.php +++ b/tests/Propel/Tests/Issues/Issue617Test.php @@ -13,6 +13,7 @@ * we really need that kind of information. * * @group mysql + * @group database */ class Issue617Test extends PlatformDatabaseBuildTimeBase { diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaFluidOperatorTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaFluidOperatorTest.php index b5524ff098..aaf95d3698 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaFluidOperatorTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaFluidOperatorTest.php @@ -18,7 +18,8 @@ * Test class for Criteria fluid operators. * * @author Francois Zaninotto - * @version $Id: CriteriaCombineTest.php 1347 2009-12-03 21:06:36Z francois $ + * + * @group database */ class CriteriaFluidOperatorTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaMergeTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaMergeTest.php index ed4f61da32..933f4955c2 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaMergeTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaMergeTest.php @@ -10,11 +10,11 @@ namespace Propel\Tests\Runtime\ActiveQuery; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Map\AuthorTableMap; use Propel\Tests\Bookstore\Map\BookTableMap; use Propel\Tests\Bookstore\Map\PublisherTableMap; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Tests\TestCaseFixtures; /** * Test class for Criteria. @@ -22,9 +22,8 @@ * @author Christopher Elkins * @author Sam Joseph */ -class CriteriaMergeTest extends BookstoreTestBase +class CriteriaMergeTest extends TestCaseFixtures { - protected function assertCriteriaTranslation($criteria, $expectedSql, $message = '') { $params = array(); diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaTest.php index 114ba55221..17fe652ed0 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaTest.php @@ -10,6 +10,7 @@ namespace Propel\Tests\Runtime\ActiveQuery; +use Propel\Runtime\Exception\PropelException; use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Map\BookTableMap; use Propel\Tests\Bookstore\BookQuery; @@ -26,6 +27,8 @@ * * @author Christopher Elkins * @author Sam Joseph + * + * @group database */ class CriteriaTest extends BookstoreTestBase { @@ -36,28 +39,28 @@ class CriteriaTest extends BookstoreTestBase */ private $c; - /** - * DB adapter saved for later. - * - * @var AbstractAdapter - */ - private $savedAdapter; +// /** +// * DB adapter saved for later. +// * +// * @var AbstractAdapter +// */ +// private $savedAdapter; protected function setUp() { parent::setUp(); $this->c = new ModelCriteria(); - $defaultDatasource = Propel::getServiceContainer()->getDefaultDatasource(); - $this->savedAdapter = Propel::getServiceContainer()->getAdapter($defaultDatasource); - $newAdapter = Propel::getServiceContainer()->getAdapter(BookTableMap::DATABASE_NAME); - Propel::getServiceContainer()->setAdapter($defaultDatasource, $newAdapter); +// $defaultDatasource = Propel::getServiceContainer()->getDefaultDatasource(); +// $this->savedAdapter = Propel::getServiceContainer()->getAdapter($defaultDatasource); +// $newAdapter = Propel::getServiceContainer()->getAdapter(BookTableMap::DATABASE_NAME); +// Propel::getServiceContainer()->setAdapter($defaultDatasource, $newAdapter); } - protected function tearDown() - { - Propel::getServiceContainer()->setAdapter(Propel::getServiceContainer()->getDefaultDatasource(), $this->savedAdapter); - parent::tearDown(); - } +// protected function tearDown() +// { +// Propel::getServiceContainer()->setAdapter(Propel::getServiceContainer()->getDefaultDatasource(), $this->savedAdapter); +// parent::tearDown(); +// } /** * Test basic adding of strings. @@ -313,12 +316,13 @@ public function testOrderByIgnoreCase() { $originalDB = Propel::getServiceContainer()->getAdapter(); Propel::getServiceContainer()->setAdapter(Propel::getServiceContainer()->getDefaultDatasource(), new MysqlAdapter()); + Propel::getServiceContainer()->setDefaultDatasource('bookstore'); $criteria = new Criteria(); $criteria->setIgnoreCase(true); $criteria->addAscendingOrderByColumn(BookTableMap::COL_TITLE); BookTableMap::addSelectColumns($criteria); - $params=array(); + $params = array(); $sql = $criteria->createSelectSql($params); $expectedSQL = 'SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, UPPER(book.TITLE) FROM `book` ORDER BY UPPER(book.TITLE) ASC'; $this->assertEquals($expectedSQL, $sql); diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaHooksTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaHooksTest.php index 08b1a11ac1..05a69aa77d 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaHooksTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaHooksTest.php @@ -20,7 +20,8 @@ * Test class for ModelCriteria. * * @author Francois Zaninotto - * @version $Id: ModelCriteriaTest.php 1662 2010-04-10 22:02:49Z francois $ + * + * @group database */ class ModelCriteriaHooksTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaSelectTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaSelectTest.php index 80afb08cca..985b9524e4 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaSelectTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaSelectTest.php @@ -21,7 +21,8 @@ * Test class for ModelCriteria select() method. * * @author Francois Zaninotto - * @version $Id: ModelCriteriaTest.php 1842 2010-07-22 22:39:40Z KRavEN $ + * + * @group database */ class ModelCriteriaSelectTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaTest.php index 5462a37189..c7f22337bc 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaTest.php @@ -45,6 +45,8 @@ * Test class for ModelCriteria. * * @author Francois Zaninotto + * + * @group database */ class ModelCriteriaTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaWithSchemaTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaWithSchemaTest.php index 7bcf26e5b9..47ac147f23 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaWithSchemaTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaWithSchemaTest.php @@ -10,20 +10,19 @@ namespace Propel\Tests\Runtime\ActiveQuery; -use Propel\Runtime\Propel; -use Propel\Tests\Helpers\Schemas\SchemasTestBase; use Propel\Tests\BookstoreSchemas\Map\BookstoreContestTableMap; -use Propel\Runtime\Map\TableMap; use Propel\Runtime\ActiveQuery\ModelCriteria; +use Propel\Tests\TestCaseFixturesDatabase; /** * Test class for ModelCriteria withs schemas. * * @author Francois Zaninotto - * @version $Id: ModelCriteriaTest.php 2090 2010-12-13 22:37:03Z francois $ + * + * @group database */ -class ModelCriteriaWithSchemaTest extends SchemasTestBase +class ModelCriteriaWithSchemaTest extends TestCaseFixturesDatabase { protected function assertCriteriaTranslation($criteria, $expectedSql, $expectedParams, $message = '') diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/ModelJoinTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/ModelJoinTest.php index 1527efccd4..0c3bb145ae 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/ModelJoinTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/ModelJoinTest.php @@ -19,14 +19,14 @@ use Propel\Runtime\ActiveQuery\ModelJoin; use Propel\Runtime\Map\TableMap; +use Propel\Tests\TestCaseFixtures; /** * Test class for ModelJoin. * * @author François Zaninotto - * @version $Id: ModelJoinTest.php 1347 2009-12-03 21:06:36Z francois $ */ -class ModelJoinTest extends BookstoreTestBase +class ModelJoinTest extends TestCaseFixtures { public function testTableMap() { diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/ModelWithTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/ModelWithTest.php index cd51a1c3d0..69f52311ef 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/ModelWithTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/ModelWithTest.php @@ -10,7 +10,6 @@ namespace Propel\Tests\Runtime\ActiveQuery; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Author; use Propel\Tests\Bookstore\AuthorQuery; use Propel\Tests\Bookstore\Book; @@ -22,14 +21,14 @@ use Propel\Tests\Bookstore\ReviewQuery; use Propel\Runtime\ActiveQuery\ModelWith; +use Propel\Tests\TestCaseFixtures; /** * Test class for ModelWith. * * @author François Zaninotto - * @version $Id: ModelJoinTest.php 1347 2009-12-03 21:06:36Z francois $ */ -class ModelWithTest extends BookstoreTestBase +class ModelWithTest extends TestCaseFixtures { public function testModelNameManyToOne() diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/PropelQueryTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/PropelQueryTest.php index 0fde23b3b8..cd17f1c963 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/PropelQueryTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/PropelQueryTest.php @@ -24,6 +24,8 @@ * Test class for PropelQuery * * @author Francois Zaninotto + * + * @group database */ class PropelQueryTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/SubQueryTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/SubQueryTest.php index c138bff6ea..895f795c59 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/SubQueryTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/SubQueryTest.php @@ -21,7 +21,8 @@ * Test class for SubQueryTest. * * @author Francois Zaninotto - * @version $Id$ + * + * @group database */ class SubQueryTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/ActiveRecordConvertTest.php b/tests/Propel/Tests/Runtime/ActiveRecordConvertTest.php index cf34a6f81a..1ed8dd2bd9 100644 --- a/tests/Propel/Tests/Runtime/ActiveRecordConvertTest.php +++ b/tests/Propel/Tests/Runtime/ActiveRecordConvertTest.php @@ -10,17 +10,17 @@ namespace Propel\Tests\Runtime\ActiveRecord; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Author; use Propel\Tests\Bookstore\Book; use Propel\Tests\Bookstore\Publisher; +use Propel\Tests\TestCaseFixtures; /** * Test class for ActiveRecord. * * @author François Zaninotto */ -class ActiveRecordConvertTest extends BookstoreTestBase +class ActiveRecordConvertTest extends TestCaseFixtures { protected function setUp() { diff --git a/tests/Propel/Tests/Runtime/ActiveRecordSerializeTest.php b/tests/Propel/Tests/Runtime/ActiveRecordSerializeTest.php index 8038517481..9fdda29154 100644 --- a/tests/Propel/Tests/Runtime/ActiveRecordSerializeTest.php +++ b/tests/Propel/Tests/Runtime/ActiveRecordSerializeTest.php @@ -20,6 +20,8 @@ * Test class for ActiveRecord serialization. * * @author Francois Zaninotto + * + * @group database */ class ActiveRecordSerializeTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/Adapter/DBAdapterTest.php b/tests/Propel/Tests/Runtime/Adapter/AbstractAdapterTest.php similarity index 98% rename from tests/Propel/Tests/Runtime/Adapter/DBAdapterTest.php rename to tests/Propel/Tests/Runtime/Adapter/AbstractAdapterTest.php index 929d3875a7..992c00426d 100644 --- a/tests/Propel/Tests/Runtime/Adapter/DBAdapterTest.php +++ b/tests/Propel/Tests/Runtime/Adapter/AbstractAdapterTest.php @@ -12,8 +12,8 @@ use Propel\Runtime\Propel; use Propel\Runtime\ActiveQuery\Criteria; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Map\BookTableMap; +use Propel\Tests\TestCaseFixtures; /** * Tests the DbOracle adapter @@ -21,7 +21,7 @@ * @see BookstoreDataPopulator * @author Francois EZaninotto */ -class AbstractAdapterTest extends BookstoreTestBase +class AbstractAdapterTest extends TestCaseFixtures { public function testTurnSelectColumnsToAliases() { diff --git a/tests/Propel/Tests/Runtime/Adapter/Pdo/MysqlAdapterTest.php b/tests/Propel/Tests/Runtime/Adapter/Pdo/MysqlAdapterTest.php index affc7c857e..e0602071a6 100644 --- a/tests/Propel/Tests/Runtime/Adapter/Pdo/MysqlAdapterTest.php +++ b/tests/Propel/Tests/Runtime/Adapter/Pdo/MysqlAdapterTest.php @@ -14,6 +14,7 @@ use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Adapter\Pdo\MysqlAdapter; +use Propel\Tests\TestCaseFixtures; /** * Tests the DbMySQL adapter @@ -21,7 +22,7 @@ * @see BookstoreDataPopulator * @author William Durand */ -class MysqlAdapterTest extends BookstoreTestBase +class MysqlAdapterTest extends TestCaseFixtures { public static function getConParams() { diff --git a/tests/Propel/Tests/Runtime/Adapter/Pdo/OracleAdapterTest.php b/tests/Propel/Tests/Runtime/Adapter/Pdo/OracleAdapterTest.php index 9e9cd41569..2658fc9666 100644 --- a/tests/Propel/Tests/Runtime/Adapter/Pdo/OracleAdapterTest.php +++ b/tests/Propel/Tests/Runtime/Adapter/Pdo/OracleAdapterTest.php @@ -14,9 +14,9 @@ use Propel\Runtime\Adapter\Pdo\OracleAdapter; use Propel\Runtime\ActiveQuery\Criteria; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Map\AuthorTableMap; use Propel\Tests\Bookstore\Map\BookTableMap; +use Propel\Tests\TestCaseFixtures; /** * Tests the DbOracle adapter @@ -24,7 +24,7 @@ * @see BookstoreDataPopulator * @author Francois EZaninotto */ -class OracleAdapterTest extends BookstoreTestBase +class OracleAdapterTest extends TestCaseFixtures { public function testApplyLimitSimple() { diff --git a/tests/Propel/Tests/Runtime/Collection/ArrayCollectionTest.php b/tests/Propel/Tests/Runtime/Collection/ArrayCollectionTest.php index 43006ad930..5efda31169 100644 --- a/tests/Propel/Tests/Runtime/Collection/ArrayCollectionTest.php +++ b/tests/Propel/Tests/Runtime/Collection/ArrayCollectionTest.php @@ -27,6 +27,8 @@ * Test class for ObjectCollection. * * @author Francois Zaninotto + * + * @group database */ class ArrayCollectionTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Collection/CollectionConvertTest.php b/tests/Propel/Tests/Runtime/Collection/CollectionConvertTest.php index ad85abb1f1..b781027779 100644 --- a/tests/Propel/Tests/Runtime/Collection/CollectionConvertTest.php +++ b/tests/Propel/Tests/Runtime/Collection/CollectionConvertTest.php @@ -13,9 +13,9 @@ use Propel\Runtime\Collection\Collection; use Propel\Runtime\Collection\ObjectCollection; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Book; use Propel\Tests\Bookstore\Publisher; +use Propel\Tests\TestCaseFixtures; /** * Test class for Collection. @@ -23,7 +23,7 @@ * @author Francois Zaninotto * @version $Id: CollectionTest.php 1348 2009-12-03 21:49:00Z francois $ */ -class CollectionConvertTest extends BookstoreTestBase +class CollectionConvertTest extends TestCaseFixtures { protected function setUp() { diff --git a/tests/Propel/Tests/Runtime/Collection/CollectionTest.php b/tests/Propel/Tests/Runtime/Collection/CollectionTest.php index d49a83ba08..3e223cc5d5 100644 --- a/tests/Propel/Tests/Runtime/Collection/CollectionTest.php +++ b/tests/Propel/Tests/Runtime/Collection/CollectionTest.php @@ -20,7 +20,8 @@ * Test class for Collection. * * @author Francois Zaninotto - * @version $Id: CollectionTest.php 1348 2009-12-03 21:49:00Z francois $ + * + * @group database */ class CollectionTest extends BookstoreTestBase { @@ -66,6 +67,101 @@ public function testSetData() $this->assertEquals($data, $col->getArrayCopy(), 'setData() sets the collection data'); } + public function testGetPosition() + { + $col = new Collection(); + $this->assertEquals(0, $col->getPosition(), 'getPosition() returns 0 on an empty collection'); + $data = array('bar1', 'bar2', 'bar3'); + $col = new Collection($data); + $expectedPositions = array(0, 1, 2); + foreach ($col as $k => $element) { + $this->assertEquals(array_shift($expectedPositions), $col->getPosition(), 'getPosition() returns the current position'); + $this->assertEquals($element, $col->getCurrent(), 'getPosition() does not change the current position'); + } + } + + public function testGetFirst() + { + $col = new Collection(); + $this->assertNull($col->getFirst(), 'getFirst() returns null on an empty collection'); + $data = array('bar1', 'bar2', 'bar3'); + $col = new Collection($data); + $this->assertEquals('bar1', $col->getFirst(), 'getFirst() returns value of the first element in the collection'); + } + + public function testIsFirst() + { + $col = new Collection(); + $this->assertTrue($col->isFirst(), 'isFirst() returns true on an empty collection'); + $data = array('bar1', 'bar2', 'bar3'); + $col = new Collection($data); + $expectedRes = array(true, false, false); + + foreach ($col as $element) { + $this->assertEquals(array_shift($expectedRes), $col->isFirst(), 'isFirst() returns true only for the first element'); + $this->assertEquals($element, $col->getCurrent(), 'isFirst() does not change the current position'); + } + } + + public function testGetPrevious() + { + $col = new Collection(); + $this->assertNull($col->getPrevious(), 'getPrevious() returns null on an empty collection'); + $data = array('bar1', 'bar2', 'bar3'); + $col = new Collection($data); + $this->assertNull($col->getPrevious(), 'getPrevious() returns null when the internal pointer is at the beginning of the list'); + $col->getNext(); + $this->assertEquals('bar1', $col->getPrevious(), 'getPrevious() returns the previous element'); + $this->assertEquals('bar1', $col->getCurrent(), 'getPrevious() decrements the internal pointer'); + } + + public function testGetCurrent() + { + $col = new Collection(); + $this->assertNull($col->getCurrent(), 'getCurrent() returns null on an empty collection'); + $data = array('bar1', 'bar2', 'bar3'); + $col = new Collection($data); + $this->assertEquals('bar1', $col->getCurrent(), 'getCurrent() returns the value of the first element when the internal pointer is at the beginning of the list'); + foreach ($col as $key => $value) { + $this->assertEquals($value, $col->getCurrent(), 'getCurrent() returns the value of the current element in the collection'); + } + } + + public function testGetNext() + { + $col = new Collection(); + $this->assertNull($col->getNext(), 'getNext() returns null on an empty collection'); + $data = array('bar1', 'bar2', 'bar3'); + $col = new Collection($data); + $this->assertEquals('bar2', $col->getNext(), 'getNext() returns the second element when the internal pointer is at the beginning of the list'); + $this->assertEquals('bar2', $col->getCurrent(), 'getNext() increments the internal pointer'); + $col->getNext(); + $this->assertNull($col->getNext(), 'getNext() returns null when the internal pointer is at the end of the list'); + } + + public function testGetLast() + { + $col = new Collection(); + $this->assertNull($col->getLast(), 'getLast() returns null on an empty collection'); + $data = array('bar1', 'bar2', 'bar3'); + $col = new Collection($data); + $this->assertEquals('bar3', $col->getLast(), 'getLast() returns the last element'); + $this->assertEquals('bar3', $col->getCurrent(), 'getLast() moves the internal pointer to the last element'); + } + + public function testIsLAst() + { + $col = new Collection(); + $this->assertTrue($col->isLast(), 'isLast() returns true on an empty collection'); + $data = array('bar1', 'bar2', 'bar3'); + $col = new Collection($data); + $expectedRes = array(false, false, true); + foreach ($col as $element) { + $this->assertEquals(array_shift($expectedRes), $col->isLast(), 'isLast() returns true only for the last element'); + $this->assertEquals($element, $col->getCurrent(), 'isLast() does not change the current position'); + } + } + public function testIsEmpty() { $col = new Collection(); @@ -223,6 +319,9 @@ public function testSerializable() $this->assertEquals($col, $col2, 'Collection is serializable'); } + /** + * @database + */ public function testGetWriteConnection() { $col = new Collection(); diff --git a/tests/Propel/Tests/Runtime/Collection/ObjectCollectionTest.php b/tests/Propel/Tests/Runtime/Collection/ObjectCollectionTest.php index dc38bb47e3..b5ae5bb4cf 100644 --- a/tests/Propel/Tests/Runtime/Collection/ObjectCollectionTest.php +++ b/tests/Propel/Tests/Runtime/Collection/ObjectCollectionTest.php @@ -23,6 +23,8 @@ * Test class for ObjectCollection. * * @author Francois Zaninotto + * + * @group database */ class ObjectCollectionTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/Collection/ObjectCollectionWithFixturesTest.php b/tests/Propel/Tests/Runtime/Collection/ObjectCollectionWithFixturesTest.php index d59cda389c..454cf8323f 100644 --- a/tests/Propel/Tests/Runtime/Collection/ObjectCollectionWithFixturesTest.php +++ b/tests/Propel/Tests/Runtime/Collection/ObjectCollectionWithFixturesTest.php @@ -26,6 +26,8 @@ * Test class for ObjectCollection. * * @author Francois Zaninotto + * + * @group database */ class ObjectCollectionWithFixturesTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Collection/OnDemandCollectionTest.php b/tests/Propel/Tests/Runtime/Collection/OnDemandCollectionTest.php index bcbc3abc95..144955389c 100644 --- a/tests/Propel/Tests/Runtime/Collection/OnDemandCollectionTest.php +++ b/tests/Propel/Tests/Runtime/Collection/OnDemandCollectionTest.php @@ -23,7 +23,8 @@ * Test class for OnDemandCollection. * * @author Francois Zaninotto - * @version $Id: ObjectCollectionTest.php 1348 2009-12-03 21:49:00Z francois $ + * + * @group database */ class OnDemandCollectionTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Collection/OnDemandIteratorTest.php b/tests/Propel/Tests/Runtime/Collection/OnDemandIteratorTest.php index 2df7c7a00b..ff7233cd39 100644 --- a/tests/Propel/Tests/Runtime/Collection/OnDemandIteratorTest.php +++ b/tests/Propel/Tests/Runtime/Collection/OnDemandIteratorTest.php @@ -21,7 +21,8 @@ * Test class for OnDemandIterator. * * @author Francois Zaninotto - * @version $Id: ObjectCollectionTest.php 1348 2009-12-03 21:49:00Z francois $ + * + * @group database */ class OnDemandIteratorTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php b/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php index ac67ca4170..64165f86e4 100644 --- a/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php +++ b/tests/Propel/Tests/Runtime/Connection/PropelPDOTest.php @@ -30,6 +30,8 @@ /** * Test for PropelPDO subclass. + * + * @group database */ class PropelPDOTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/ArrayFormatterTest.php b/tests/Propel/Tests/Runtime/Formatter/ArrayFormatterTest.php index d365ab383b..877ac43e74 100644 --- a/tests/Propel/Tests/Runtime/Formatter/ArrayFormatterTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/ArrayFormatterTest.php @@ -23,7 +23,8 @@ * Test class for ArrayFormatter. * * @author Francois Zaninotto - * @version $Id$ + * + * @group database */ class ArrayFormatterTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/ArrayFormatterWithTest.php b/tests/Propel/Tests/Runtime/Formatter/ArrayFormatterWithTest.php index aa2d10ae49..7e9b021262 100644 --- a/tests/Propel/Tests/Runtime/Formatter/ArrayFormatterWithTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/ArrayFormatterWithTest.php @@ -30,6 +30,8 @@ * Test class for ArrayFormatter when Criteria uses with(). * * @author Francois Zaninotto + * + * @group database */ class ArrayFormatterWithTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/DataFetcherTest.php b/tests/Propel/Tests/Runtime/Formatter/DataFetcherTest.php index 5293cad2a1..91cbc91d1c 100644 --- a/tests/Propel/Tests/Runtime/Formatter/DataFetcherTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/DataFetcherTest.php @@ -19,6 +19,8 @@ /** * Test class for DataFetcher. + * + * @group database */ class DataFetcherTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterInheritanceTest.php b/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterInheritanceTest.php index 97fbff1a35..fa57054ee1 100644 --- a/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterInheritanceTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterInheritanceTest.php @@ -24,6 +24,8 @@ * Test class for ObjectFormatter. * * @author Francois Zaninotto + * + * @group database */ class ObjectFormatterInheritanceTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterTest.php b/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterTest.php index b3ac4cc5d4..04734bcd7f 100644 --- a/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterTest.php @@ -27,7 +27,8 @@ * Test class for ObjectFormatter. * * @author Francois Zaninotto - * @version $Id$ + * + * @group database */ class ObjectFormatterTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterWithTest.php b/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterWithTest.php index 196afd4c85..8de39e5cca 100644 --- a/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterWithTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/ObjectFormatterWithTest.php @@ -37,6 +37,8 @@ * Test class for ObjectFormatter when Criteria uses with(). * * @author Francois Zaninotto + * + * @group database */ class ObjectFormatterWithTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/OnDemandFormatterTest.php b/tests/Propel/Tests/Runtime/Formatter/OnDemandFormatterTest.php index b28b5c1d90..419adcc899 100644 --- a/tests/Propel/Tests/Runtime/Formatter/OnDemandFormatterTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/OnDemandFormatterTest.php @@ -27,6 +27,8 @@ * Test class for OnDemandFormatter. * * @author Francois Zaninotto + * + * @group database */ class OnDemandFormatterTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/OnDemandFormatterWithTest.php b/tests/Propel/Tests/Runtime/Formatter/OnDemandFormatterWithTest.php index 0c9ace34e5..dedcc48ffb 100644 --- a/tests/Propel/Tests/Runtime/Formatter/OnDemandFormatterWithTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/OnDemandFormatterWithTest.php @@ -29,6 +29,8 @@ * Test class for OnDemandFormatter when Criteria uses with(). * * @author Francois Zaninotto + * + * @group database */ class OnDemandFormatterWithTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Formatter/SimpleArrayFormatterTest.php b/tests/Propel/Tests/Runtime/Formatter/SimpleArrayFormatterTest.php index 374b347c39..83bd52a465 100644 --- a/tests/Propel/Tests/Runtime/Formatter/SimpleArrayFormatterTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/SimpleArrayFormatterTest.php @@ -17,6 +17,9 @@ use Propel\Tests\Helpers\Bookstore\BookstoreEmptyTestBase; use Propel\Tests\Helpers\Bookstore\BookstoreDataPopulator; +/** + * @group database + */ class SimpleArrayFormatterTest extends BookstoreEmptyTestBase { protected function setUp() diff --git a/tests/Propel/Tests/Runtime/Formatter/StatementFormatterTest.php b/tests/Propel/Tests/Runtime/Formatter/StatementFormatterTest.php index 145957fd72..9023dac0d4 100644 --- a/tests/Propel/Tests/Runtime/Formatter/StatementFormatterTest.php +++ b/tests/Propel/Tests/Runtime/Formatter/StatementFormatterTest.php @@ -29,6 +29,8 @@ * Test class for StatementFormatter. * * @author Francois Zaninotto + * + * @group database */ class StatementFormatterTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Map/ColumnMapTest.php b/tests/Propel/Tests/Runtime/Map/ColumnMapTest.php index 5c17c4da24..bca3cc0409 100644 --- a/tests/Propel/Tests/Runtime/Map/ColumnMapTest.php +++ b/tests/Propel/Tests/Runtime/Map/ColumnMapTest.php @@ -10,7 +10,6 @@ namespace Propel\Tests\Runtime\Map; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; use Propel\Tests\Bookstore\Map\BookTableMap; use Propel\Tests\Bookstore\Map\BookstoreEmployeeTableMap; @@ -18,14 +17,14 @@ use Propel\Runtime\Map\DatabaseMap; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Map\Exception\ForeignKeyNotFoundException; +use Propel\Tests\TestCaseFixtures; /** * Test class for TableMap. * * @author François Zaninotto - * @version $Id$ */ -class ColumnMapTest extends BookstoreTestBase +class ColumnMapTest extends TestCaseFixtures { protected $databaseMap; diff --git a/tests/Propel/Tests/Runtime/Map/DatabaseMapTest.php b/tests/Propel/Tests/Runtime/Map/DatabaseMapTest.php index 8232ad0b9f..3206e456ef 100644 --- a/tests/Propel/Tests/Runtime/Map/DatabaseMapTest.php +++ b/tests/Propel/Tests/Runtime/Map/DatabaseMapTest.php @@ -10,22 +10,20 @@ namespace Propel\Tests\Runtime\Map; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; - use Propel\Runtime\Propel; use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\DatabaseMap; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Map\Exception\ColumnNotFoundException; use Propel\Runtime\Map\Exception\TableNotFoundException; +use Propel\Tests\TestCaseFixtures; /** * Test class for DatabaseMap. * * @author François Zaninotto - * @version $Id$ */ -class DatabaseMapTest extends BookstoreTestBase +class DatabaseMapTest extends TestCaseFixtures { protected $databaseMap; diff --git a/tests/Propel/Tests/Runtime/Map/GeneratedRelationMapTest.php b/tests/Propel/Tests/Runtime/Map/GeneratedRelationMapTest.php index 5aa3b72a2d..58b03a7aca 100644 --- a/tests/Propel/Tests/Runtime/Map/GeneratedRelationMapTest.php +++ b/tests/Propel/Tests/Runtime/Map/GeneratedRelationMapTest.php @@ -10,18 +10,16 @@ namespace Propel\Tests\Runtime\Map; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; - use Propel\Runtime\Propel; use Propel\Runtime\Map\RelationMap; +use Propel\Tests\TestCaseFixtures; /** * Test class for PHP5TableMapBuilder. * * @author François Zaninotto - * @version $Id$ */ -class GeneratedRelationMapTest extends BookstoreTestBase +class GeneratedRelationMapTest extends TestCaseFixtures { protected $databaseMap; diff --git a/tests/Propel/Tests/Runtime/Map/GeneratedRelationMapWithSchemasTest.php b/tests/Propel/Tests/Runtime/Map/GeneratedRelationMapWithSchemasTest.php index 7c18bb0fbe..e524dbcd24 100644 --- a/tests/Propel/Tests/Runtime/Map/GeneratedRelationMapWithSchemasTest.php +++ b/tests/Propel/Tests/Runtime/Map/GeneratedRelationMapWithSchemasTest.php @@ -10,19 +10,18 @@ namespace Propel\Tests\Runtime\Map; -use Propel\Tests\BookstoreSchemas\Map\BookstoreContestTableMap; -use Propel\Tests\Helpers\Schemas\SchemasTestBase; - use Propel\Runtime\Propel; use Propel\Runtime\Map\RelationMap; +use Propel\Tests\TestCaseFixturesDatabase; /** * Test class for PHP5TableMapBuilder with schemas. * * @author Ulf Hermann - * @version $Id$ + * + * @group database */ -class GeneratedRelationMapWithSchemasTest extends SchemasTestBase +class GeneratedRelationMapWithSchemasTest extends TestCaseFixturesDatabase { /** * @var \Propel\Runtime\Map\DatabaseMap diff --git a/tests/Propel/Tests/Runtime/Map/RelatedMapSymmetricalTest.php b/tests/Propel/Tests/Runtime/Map/RelatedMapSymmetricalTest.php index bebe21aebb..cd8ed28da7 100644 --- a/tests/Propel/Tests/Runtime/Map/RelatedMapSymmetricalTest.php +++ b/tests/Propel/Tests/Runtime/Map/RelatedMapSymmetricalTest.php @@ -10,17 +10,15 @@ namespace Propel\Tests\Runtime\Map; -use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; - use Propel\Runtime\Propel; +use Propel\Tests\TestCaseFixtures; /** * Test class for RelatedMap::getSymmetricalRelation. * * @author François Zaninotto - * @version $Id: GeneratedRelationMapTest.php 1347 2009-12-03 21:06:36Z francois $ */ -class RelatedMapSymmetricalTest extends BookstoreTestBase +class RelatedMapSymmetricalTest extends TestCaseFixtures { protected $databaseMap; diff --git a/tests/Propel/Tests/Runtime/Map/RelatedMapSymmetricalWithSchemasTest.php b/tests/Propel/Tests/Runtime/Map/RelatedMapSymmetricalWithSchemasTest.php index 33fd5a4223..9fad38ffd6 100644 --- a/tests/Propel/Tests/Runtime/Map/RelatedMapSymmetricalWithSchemasTest.php +++ b/tests/Propel/Tests/Runtime/Map/RelatedMapSymmetricalWithSchemasTest.php @@ -11,16 +11,16 @@ namespace Propel\Tests\Runtime\Map; use Propel\Runtime\Propel; - -use Propel\Tests\Helpers\Schemas\SchemasTestBase; +use Propel\Tests\TestCaseFixturesDatabase; /** * Test class for RelatedMap::getSymmetricalRelation with schemas. * * @author Ulf Hermann - * @version $Id$ + * + * @group database */ -class RelatedMapSymmetricalWithSchemasTest extends SchemasTestBase +class RelatedMapSymmetricalWithSchemasTest extends TestCaseFixturesDatabase { protected $databaseMap; diff --git a/tests/Propel/Tests/Runtime/Util/PropelModelPagerTest.php b/tests/Propel/Tests/Runtime/Util/PropelModelPagerTest.php index b662a0e46f..fed744115e 100644 --- a/tests/Propel/Tests/Runtime/Util/PropelModelPagerTest.php +++ b/tests/Propel/Tests/Runtime/Util/PropelModelPagerTest.php @@ -23,6 +23,8 @@ * Test the utility class PropelModelPager * * @author Francois Zaninotto + * + * @group database */ class PropelModelPagerTest extends BookstoreEmptyTestBase { diff --git a/tests/Propel/Tests/Runtime/Util/TableMapExceptionsTest.php b/tests/Propel/Tests/Runtime/Util/TableMapExceptionsTest.php index 10e0fbbbf7..f3aa1479a3 100644 --- a/tests/Propel/Tests/Runtime/Util/TableMapExceptionsTest.php +++ b/tests/Propel/Tests/Runtime/Util/TableMapExceptionsTest.php @@ -22,6 +22,8 @@ * * @see BookstoreDataPopulator * @author Francois Zaninotto + * + * @group database */ class TableMapExceptionsTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/Runtime/Util/TableMapTest.php b/tests/Propel/Tests/Runtime/Util/TableMapTest.php index 7a0fdf3f6a..9f66722549 100644 --- a/tests/Propel/Tests/Runtime/Util/TableMapTest.php +++ b/tests/Propel/Tests/Runtime/Util/TableMapTest.php @@ -27,6 +27,8 @@ * * @see BookstoreDataPopulator * @author Hans Lellelid + * + * @group database */ class TableMapTest extends BookstoreTestBase { diff --git a/tests/Propel/Tests/TestCase.php b/tests/Propel/Tests/TestCase.php index d372fc035a..9d10f74a5d 100644 --- a/tests/Propel/Tests/TestCase.php +++ b/tests/Propel/Tests/TestCase.php @@ -10,24 +10,13 @@ namespace Propel\Tests; -use Propel\Generator\Command\TestPrepareCommand; -use Propel\Runtime\Propel; -use Symfony\Component\Console\Application; -use Propel\Runtime\Connection\ConnectionInterface; -use Symfony\Component\Finder\Finder; -/** - * @author William Durand - */ -class TestCase extends \PHPUnit_Framework_TestCase +class TestCase extends \PHPUnit_Framework_TestCase { - /** - * Depending on this type we return the correct runninOn* results, - * also getSql() and getDriver() is based on that. - * - * @var ConnectionInterface - */ - protected $con; + protected function getDriver() + { + return 'sqlite'; + } /** * Makes the sql compatible with the current database. @@ -54,130 +43,6 @@ protected function getSql($sql, $source = 'mysql', $target = null) return $sql; } - /** - * Setup fixture. Needed here because we want to have a realistic code coverage value. - */ - protected function setUp() - { - - $dsn = $this->getFixturesConnectionDsn(); - - if ($dsn === $this->getBuiltDsn()) { - $this->readAllRuntimeConfigs(); - //skip, as we've already created all fixtures for current database connection. - return; - } - - $builtInfo = 'tests/Fixtures/fixtures_built'; - file_put_contents($builtInfo, - "$dsn\nFixtures has been created. Delete this file to let the test suite regenerate all fixtures." - ); - - $finder = new Finder(); - $finder->files()->name('*.php')->in(__DIR__.'/../../../src/Propel/Generator/Command'); - - $app = new Application('Propel', Propel::VERSION); - - foreach ($finder as $file) { - $ns = '\\Propel\\Generator\\Command'; - $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php')); - if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) { - $app->add($r->newInstance()); - } - } - - $options = array( - 'command' => 'test:prepare', - '--vendor' => $this->getDriver(), - '--dsn' => $dsn, - '--verbose' - ); - - if (0 !== strpos($dsn, 'sqlite:')) { - $options['--user'] = getenv('DB_USER') ?: 'root'; - } - - if (false !== getenv('DB_PASSWORD')) { - $options['--password'] = getenv('DB_PASSWORD'); - } - - $input = new \Symfony\Component\Console\Input\ArrayInput($options); - - $output = new \Symfony\Component\Console\Output\ConsoleOutput(); - $app->setAutoExit(false); - $app->run($input, $output); - - $this->readAllRuntimeConfigs(); - } - - /** - * Reads and includes all *-conf.php of Fixtures/ folder. - */ - protected function readAllRuntimeConfigs() - { - $finder = new Finder(); - $finder->files()->name('*-conf.php')->in(__DIR__.'/../../Fixtures/'); - - foreach ($finder as $file) { - include_once($file->getPathname()); - } - } - - /** - * Returns the used DNS for building the fixtures. - * - * @return string - */ - protected function getBuiltDsn() - { - $builtInfo = 'tests/Fixtures/fixtures_built'; - if (file_exists($builtInfo) && ($h = fopen($builtInfo, 'r')) && $firstLine = fgets($h)) { - return trim($firstLine); - } - } - - /** - * Returns the current connection DSN. - * - * @param string $database - * @param boolean $withCredentials - * @return string - */ - protected function getConnectionDsn($database = 'bookstore', $withCredentials = false) - { - $serviceContainer = \Propel\Runtime\Propel::getServiceContainer(); - /** @var $manager \Propel\Runtime\Connection\ConnectionManagerSingle */ - $manager = $serviceContainer->getConnectionManager($database); - $configuration = $manager->getConfiguration(); - $dsn = $configuration['dsn']; - - if ($withCredentials) { - $dsn .= ';user=' . $configuration['user']; - if (isset($configuration['password']) && $configuration['password']) { - $dsn .= ';password=' . $configuration['password']; - } - } - - return $dsn; - } - - /** - * Returns the DSN for building the fixtures. - * They are provided by environment variables. - * - * DB, DB_HOSTNAME - * - * @return string - */ - protected function getFixturesConnectionDsn() - { - if ('sqlite' === strtolower(getenv('DB'))) { - return 'sqlite:' . realpath(__DIR__ . '/../../test.sq3'); - } - - return (strtolower(getenv('DB')) ?: 'mysql') . ':host=' . (getenv('DB_HOSTNAME') ?: '127.0.0.1' ) . ';dbname=test'; - } - /** * Returns true if the current driver in the connection ($this->con) is $db. * diff --git a/tests/Propel/Tests/TestCaseFixtures.php b/tests/Propel/Tests/TestCaseFixtures.php new file mode 100644 index 0000000000..1f3bd3ce38 --- /dev/null +++ b/tests/Propel/Tests/TestCaseFixtures.php @@ -0,0 +1,223 @@ + + */ +class TestCaseFixtures extends TestCase +{ + /** + * If setUp() should also initial database's schema. + * + * @var bool + */ + protected static $withDatabaseSchema = false; + + /** + * Depending on this type we return the correct runninOn* results, + * also getSql() and getDriver() is based on that. + * + * @var ConnectionInterface + */ + protected $con; + + /** + * Setup fixture. Needed here because we want to have a realistic code coverage value. + */ + protected function setUp() + { + $dsn = $this->getFixturesConnectionDsn(); + + $options = array( + 'command' => 'test:prepare', + '--vendor' => $this->getDriver(), + '--dsn' => $dsn, + '--verbose' => true + ); + + if (!static::$withDatabaseSchema) { + $options['--exclude-schema'] = true; + } + + $mode = static::$withDatabaseSchema ? 'fixtures-database' : 'fixtures-only'; + $builtMode = $this->getLastBuildMode(); + + if ($dsn === $this->getBuiltDsn()) { + // we have at least the fixtures built + + // when we need a database update ($withDatabaseSchema == true) then we need to check + // if the last build was a test:prepare with database or not. When yes then skip. + $skip = true; + if (static::$withDatabaseSchema && 'fixtures-database' !== $builtMode) { + //we need new test:prepare call with --exclude-schema disabled + $skip = false; + } + + if ($skip) { + $this->readAllRuntimeConfigs(); + //skip, as we've already created all fixtures for current database connection. + return; + } + } + + $finder = new Finder(); + $finder->files()->name('*.php')->in(__DIR__.'/../../../src/Propel/Generator/Command'); + + $app = new Application('Propel', Propel::VERSION); + + foreach ($finder as $file) { + $ns = '\\Propel\\Generator\\Command'; + $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php')); + if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) { + $app->add($r->newInstance()); + } + } + if (0 !== strpos($dsn, 'sqlite:')) { + $options['--user'] = getenv('DB_USER') ?: 'root'; + } + + if (false !== getenv('DB_PW')) { + $options['--password'] = getenv('DB_PW'); + } + + $input = new \Symfony\Component\Console\Input\ArrayInput($options); + + $output = new \Symfony\Component\Console\Output\BufferedOutput(); + $app->setAutoExit(false); + if (0 !== $app->run($input, $output)) { + echo $output->fetch(); + $this->fail('Can not initialize fixtures.'); + return false; + } + + + $builtInfo = __DIR__ . '/../../Fixtures/fixtures_built'; + file_put_contents($builtInfo, + "$dsn\n$mode\nFixtures has been created. Delete this file to let the test suite regenerate all fixtures." + ); + + $this->readAllRuntimeConfigs(); + } + + protected function getLastBuildMode() + { + $builtInfo = __DIR__ . '/../../Fixtures/fixtures_built'; + if (file_exists($builtInfo) && ($h = fopen($builtInfo, 'r'))) { + fgets($h); + $secondLine = fgets($h); + return trim($secondLine); + } + } + + /** + * Reads and includes all *-conf.php of Fixtures/ folder. + */ + protected function readAllRuntimeConfigs() + { + $finder = new Finder(); + $finder->files()->name('*-conf.php')->in(__DIR__.'/../../Fixtures/'); + + foreach ($finder as $file) { + include_once($file->getPathname()); + } + } + + /** + * Returns the used DNS for building the fixtures. + * + * @return string + */ + protected function getBuiltDsn() + { + $builtInfo = __DIR__ . '/../../Fixtures/fixtures_built'; + if (file_exists($builtInfo) && ($h = fopen($builtInfo, 'r')) && $firstLine = fgets($h)) { + return trim($firstLine); + } + } + + /** + * Returns the current connection DSN. + * + * @param string $database + * @param boolean $withCredentials + * @return string + */ + protected function getConnectionDsn($database = 'bookstore', $withCredentials = false) + { + $serviceContainer = \Propel\Runtime\Propel::getServiceContainer(); + /** @var $manager \Propel\Runtime\Connection\ConnectionManagerSingle */ + $manager = $serviceContainer->getConnectionManager($database); + $configuration = $manager->getConfiguration(); + $dsn = $configuration['dsn']; + + if ('sqlite' !== substr($dsn, 0, 6) && $withCredentials) { + $dsn .= ';user=' . $configuration['user']; + if (isset($configuration['password']) && $configuration['password']) { + $dsn .= ';password=' . $configuration['password']; + } + } + + return $dsn; + } + + /** + * Returns the DSN for building the fixtures. + * They are provided by environment variables. + * + * DB, DB_HOSTNAME + * + * @return string + */ + protected function getFixturesConnectionDsn() + { + if ('sqlite' === strtolower(getenv('DB'))) { + $path = __DIR__ . '/../../test.sq3'; + if (!file_exists($path)) { + touch($path); + } + return 'sqlite:' . realpath($path); + } + + $dsn = (strtolower(getenv('DB')) ?: 'mysql') . ':host=' . (getenv('DB_HOSTNAME') ?: '127.0.0.1' ) . ';dbname='; + $dsn .= getenv('DB_NAME') ?: 'test'; + + return $dsn; + } + + + /** + * Returns current database driver. + * + * @return string[] + */ + protected function getDriver() + { + $driver = $this->con ? $this->con->getAttribute(\PDO::ATTR_DRIVER_NAME) : null; + + if (null === $driver && $currentDSN = $this->getBuiltDsn()) { + $driver = explode(':', $currentDSN)[0]; + } + + return strtolower($driver) ?: (strtolower(getenv('DB')) ?: 'mysql'); + } +} diff --git a/tests/Propel/Tests/TestCaseFixturesDatabase.php b/tests/Propel/Tests/TestCaseFixturesDatabase.php new file mode 100644 index 0000000000..afa32b38a6 --- /dev/null +++ b/tests/Propel/Tests/TestCaseFixturesDatabase.php @@ -0,0 +1,28 @@ + + */ +class TestCaseFixturesDatabase extends TestCaseFixtures +{ + protected static $withDatabaseSchema = true; +} diff --git a/tests/Propel/Tests/Ticket520Test.php b/tests/Propel/Tests/Ticket520Test.php index fe97dfa15b..8e431d8ba9 100644 --- a/tests/Propel/Tests/Ticket520Test.php +++ b/tests/Propel/Tests/Ticket520Test.php @@ -16,11 +16,8 @@ use Propel\Tests\Bookstore\Map\BookTableMap; use Propel\Tests\Helpers\Bookstore\BookstoreTestBase; -/* It's only fair to admit that these tests were carefully crafted -after studying the current implementation to make it look as bad as -possible. I am really sorry. :-( */ - /** + * @group database */ class Ticket520Test extends BookstoreTestBase { diff --git a/tests/bin/phpunit.agnostic.sh b/tests/bin/phpunit.agnostic.sh new file mode 100755 index 0000000000..c6f7477d98 --- /dev/null +++ b/tests/bin/phpunit.agnostic.sh @@ -0,0 +1,2 @@ +#!/bin/sh +phpunit -v --exclude-group database; \ No newline at end of file diff --git a/tests/bin/phpunit.mysql.sh b/tests/bin/phpunit.mysql.sh index 1caa5a1ff1..c4b87a4c84 100755 --- a/tests/bin/phpunit.mysql.sh +++ b/tests/bin/phpunit.mysql.sh @@ -1,2 +1,2 @@ #!/bin/sh -phpunit; \ No newline at end of file +phpunit --group database; diff --git a/tests/bin/phpunit.pgsql.sh b/tests/bin/phpunit.pgsql.sh index 4a3a9e600e..f0a7674d32 100755 --- a/tests/bin/phpunit.pgsql.sh +++ b/tests/bin/phpunit.pgsql.sh @@ -1,2 +1,2 @@ #!/bin/sh -phpunit --exclude-group mysql; \ No newline at end of file +phpunit --group database --exclude-group mysql; \ No newline at end of file diff --git a/tests/bin/phpunit.sqlite.sh b/tests/bin/phpunit.sqlite.sh index 4a3a9e600e..f0a7674d32 100755 --- a/tests/bin/phpunit.sqlite.sh +++ b/tests/bin/phpunit.sqlite.sh @@ -1,2 +1,2 @@ #!/bin/sh -phpunit --exclude-group mysql; \ No newline at end of file +phpunit --group database --exclude-group mysql; \ No newline at end of file