Skip to content

Commit

Permalink
Separated database agnostics tests and integration tests.
Browse files Browse the repository at this point in the history
Conflicts:
	.coveralls.yml
	.travis.yml
	src/Propel/Generator/Command/MigrationUpCommand.php
	tests/Propel/Tests/Generator/Behavior/Sluggable/SluggableBehaviorTest.php
	tests/Propel/Tests/Runtime/Collection/CollectionTest.php
	tests/Propel/Tests/TestCase.php
	tests/bin/phpunit.mysql.sh
  • Loading branch information
Marc J. Schmidt committed Apr 17, 2014
1 parent f745366 commit 2e076c4
Show file tree
Hide file tree
Showing 112 changed files with 724 additions and 425 deletions.
4 changes: 4 additions & 0 deletions .coveralls.yml
@@ -0,0 +1,4 @@
service_name: travis-ci
src_dir: src
json_path: tests/coveralls.json
coverage_clover: tests/clover.xml
15 changes: 12 additions & 3 deletions .travis.yml
Expand Up @@ -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
Expand All @@ -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
56 changes: 35 additions & 21 deletions phpunit.xml.dist
Expand Up @@ -9,27 +9,41 @@
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
>

<testsuites>
<testsuite name="Propel2 Test Suite">
<directory>./tests/Propel/Tests/</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Propel2 Test Suite">
<directory>./tests/Propel/Tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/Propel/</directory>
<exclude>
<directory>./bin</directory>
<directory>./documentation</directory>
<directory>./features</directory>
<directory>./resources</directory>
<directory>./src/Propel/Generator/Behavior/*/templates/</directory>
<directory>./tests</directory>
<directory>./tools</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="../clover.xml"/>
</logging>

<filter>
<whitelist>
<directory>../../src/Propel/</directory>
<exclude>
<directory>../../src/Propel/Generator/Builder/SQL/Mssql</directory>
<directory>../../src/Propel/Generator/Builder/SQL/Oracle</directory>
<directory>../../src/Propel/Generator/Builder/SQL/Sqlsrv</directory>

<file>../../src/Propel/Generator/Platform/MssqlPlatform.php</file>
<file>../../src/Propel/Generator/Platform/OraclePlatform.php</file>
<file>../../src/Propel/Generator/Platform/SqlsrvPlatform.php</file>

<file>../../src/Propel/Generator/Reverse/MssqlSchemaParser.php</file>
<file>../../src/Propel/Generator/Reverse/OracleSchemaParser.php</file>
<file>../../src/Propel/Generator/Reverse/SqlsrvSchemaParser.php</file>

<directory>../../src/Propel/Runtime/Adapter/MSSQL</directory>
<file>../../src/Propel/Runtime/Adapter/Pdo/MssqlAdapter.php</file>
<file>../../src/Propel/Runtime/Adapter/Pdo/OracleAdapter.php</file>
<file>../../src/Propel/Runtime/Adapter/Pdo/SqlsrvAdapter.php</file>

<file>../../src/Propel/Runtime/Adapter/Pdo/SqlsrvAdapter.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
2 changes: 2 additions & 0 deletions src/Propel/Generator/Command/MigrationUpCommand.php
Expand Up @@ -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')) {
Expand All @@ -116,6 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new RuntimeException(sprintf('<error>Failed to execute SQL "%s". Aborting migration.</error>', $statement), 0, $e);
}
}
$conn->commit();
if (!$res) {
$output->writeln('No statement was executed. The version was not updated.');
$output->writeln(sprintf(
Expand Down
63 changes: 34 additions & 29 deletions src/Propel/Generator/Command/TestPrepareCommand.php
Expand Up @@ -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')
Expand All @@ -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('<error>Directory "%s" not found.</error>', $fixturesDir));

return;
return 1;
}

$output->writeln(sprintf('Building fixtures in <info>%-40s</info> ', $fixturesDir));
$output->writeln(sprintf('Building fixtures in <info>%-40s</info> ' . ($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',
Expand All @@ -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',
Expand Down Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/Propel/Generator/Manager/MigrationManager.php
Expand Up @@ -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])) {
Expand Down
2 changes: 0 additions & 2 deletions src/Propel/Generator/Platform/SqlitePlatform.php
Expand Up @@ -233,7 +233,6 @@ public function getMigrationTableDDL(TableDiff $tableDiff)
public function getBeginDDL()
{
return '
END;
PRAGMA foreign_keys = OFF;
';
}
Expand All @@ -242,7 +241,6 @@ public function getEndDDL()
{
return '
PRAGMA foreign_keys = ON;
BEGIN;
';
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Propel/Tests/BookstoreTest.php
Expand Up @@ -39,6 +39,8 @@
*
* @author Francois Zaninotto
* @author Hans Lellelid <hans@xmpl.org>
*
* @group database
*/
class BookstoreTest extends BookstoreEmptyTestBase
{
Expand Down
2 changes: 2 additions & 0 deletions tests/Propel/Tests/CharacterEncodingTest.php
Expand Up @@ -36,6 +36,8 @@
*
* @see BookstoreDataPopulator
* @author Hans Lellelid <hans@xmpl.org>
*
* @group database
*/
class CharacterEncodingTest extends BookstoreTestBase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Propel/Tests/FieldnameRelatedTest.php
Expand Up @@ -33,7 +33,7 @@
*
* @author Sven Fuchs <svenfuchs@artweb-design.de>
*/
class FieldnameRelatedTest extends TestCase
class FieldnameRelatedTest extends TestCaseFixtures
{
/**
* Tests if fieldname type constants are defined
Expand Down
Expand Up @@ -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()
{
Expand Down
Expand Up @@ -28,6 +28,8 @@
* Tests for AggregateColumnBehavior class
*
* @author François Zaninotto
*
* @group database
*/
class AggregateColumnBehaviorTest extends BookstoreTestBase
{
Expand All @@ -37,7 +39,6 @@ protected function setUp()
include_once(__DIR__.'/AggregateColumnsBehaviorTestClasses.php');
}


public function testParameters()
{
$postTable = AggregatePostTableMap::getTableMap();
Expand Down
Expand Up @@ -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();
Expand All @@ -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');
}
}

0 comments on commit 2e076c4

Please sign in to comment.