Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
tests/DoctrineTest/doctrine_tests/*
*TestCase.php
*TestCase.php
/tests/tmp
/tests/foo.sq3
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ jobs:
- php: 5.6
dist: trusty

services:
- mysql

before_install:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'

install:
- composer install --prefer-dist --no-progress --no-suggest -o
- composer install --prefer-dist --no-progress --no-suggest -o

script:
- php -dshort_open_tag=Off -dmagic_quotes_gpc=Off tests/index.php
- "cd tests && php -dshort_open_tag=Off -dmagic_quotes_gpc=Off run.php"
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
],
"require": {
"php": ">=5.3",
"ext-zlib": "*",
"ext-mbstring": "*",
"ext-pdo": "*"
},
Expand Down
24 changes: 15 additions & 9 deletions lib/Doctrine/Record/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,24 @@ public function init()
}

/**
* filterSet
* defines an implementation for filtering the set() method of Doctrine_Record
* Provides a way for setting property or relation value to the given record.
*
* @param mixed $name name of the property or related component
* @param string $propertyOrRelation
*
* @return Doctrine_Record the given record
*
* @thrown Doctrine_Exception when this way is not available
*/
abstract public function filterSet(Doctrine_Record $record, $name, $value);
abstract public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value);

/**
* filterGet
* defines an implementation for filtering the get() method of Doctrine_Record
* Provides a way for getting property or relation value from the given record.
*
* @param string $propertyOrRelation
*
* @return mixed
*
* @param mixed $name name of the property or related component
* @thrown Doctrine_Exception when this way is not available
*/
abstract public function filterGet(Doctrine_Record $record, $name);
}
abstract public function filterGet(Doctrine_Record $record, $propertyOrRelation);
}
69 changes: 46 additions & 23 deletions lib/Doctrine/Record/Filter/Compound.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,66 +32,89 @@
*/
class Doctrine_Record_Filter_Compound extends Doctrine_Record_Filter
{
/**
* @var string[]
*/
protected $_aliases = array();

/**
* @param string[] $aliases A list of relation name
*/
public function __construct(array $aliases)
{
$this->_aliases = $aliases;
}

/**
* @throws Doctrine_Table_Exception when at least one configured alias is not a relation
*/
public function init()
{
// check that all aliases exist
foreach ($this->_aliases as $alias) {
// check that all aliases exist
foreach ($this->_aliases as $alias) {
$this->_table->getRelation($alias);
}
}
}

/**
* filterSet
* defines an implementation for filtering the set() method of Doctrine_Record
* Provides a way for setting property or relation value to the given record.
*
* @param mixed $name name of the property or related component
* @param string $propertyOrRelation
*
* @return Doctrine_Record the given record
*
* @thrown Doctrine_Record_UnknownPropertyException when this way is not available
*/
public function filterSet(Doctrine_Record $record, $name, $value)
public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value)
{
foreach ($this->_aliases as $alias) {
// The relationship must be fetched in order to check the field existence.
// Related to PHP-7.0 compatibility so an explicit call to method get is required.
$record[$alias];

if ( ! $record->exists()) {
if (isset($record[$alias][$name])) {
$record[$alias][$name] = $value;
if (isset($record[$alias][$propertyOrRelation])) {
$record[$alias][$propertyOrRelation] = $value;

return $record;
}
} else {
if (isset($record[$alias][$name])) {
$record[$alias][$name] = $value;
if (isset($record[$alias][$propertyOrRelation])) {
$record[$alias][$propertyOrRelation] = $value;
}

return $record;
}
}
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record)));
}

/**
* filterGet
* defines an implementation for filtering the get() method of Doctrine_Record
* Provides a way for getting property or relation value from the given record.
*
* @param mixed $name name of the property or related component
* @param string $propertyOrRelation
*
* @return mixed
*
* @thrown Doctrine_Record_UnknownPropertyException when this way is not available
*/
public function filterGet(Doctrine_Record $record, $name)
public function filterGet(Doctrine_Record $record, $propertyOrRelation)
{
foreach ($this->_aliases as $alias) {
// The relationship must be fetched in order to check the field existence.
// Related to PHP-7.0 compatibility so an explicit call to method get is required.
$record[$alias];

if ( ! $record->exists()) {
if (isset($record[$alias][$name])) {
return $record[$alias][$name];
if (isset($record[$alias][$propertyOrRelation])) {
return $record[$alias][$propertyOrRelation];
}
} else {
if (isset($record[$alias][$name])) {
return $record[$alias][$name];
if (isset($record[$alias][$propertyOrRelation])) {
return $record[$alias][$propertyOrRelation];
}
}
}
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record)));
}
}
}
18 changes: 8 additions & 10 deletions lib/Doctrine/Record/Filter/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,22 @@
class Doctrine_Record_Filter_Standard extends Doctrine_Record_Filter
{
/**
* filterSet
* defines an implementation for filtering the set() method of Doctrine_Record
* @param string $propertyOrRelation
*
* @param mixed $name name of the property or related component
* @thrown Doctrine_Record_UnknownPropertyException
*/
public function filterSet(Doctrine_Record $record, $name, $value)
public function filterSet(Doctrine_Record $record, $propertyOrRelation, $value)
{
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record)));
}

/**
* filterGet
* defines an implementation for filtering the get() method of Doctrine_Record
* @param string $propertyOrRelation
*
* @param mixed $name name of the property or related component
* @thrown Doctrine_Record_UnknownPropertyException
*/
public function filterGet(Doctrine_Record $record, $name)
public function filterGet(Doctrine_Record $record, $propertyOrRelation)
{
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $propertyOrRelation, get_class($record)));
}
}
4 changes: 4 additions & 0 deletions lib/Doctrine/Search/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function indexDirectory($dir)
continue;
}

if ($file->isDir()) {
continue;
}

$this->updateIndex(array('url' => $file->getPathName(),
'content' => file_get_contents($file)));
}
Expand Down
21 changes: 11 additions & 10 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @since 1.0
* @version $Revision$
*/
class Doctrine_Base_TestCase extends Doctrine_UnitTestCase
class Doctrine_Base_TestCase extends Doctrine_UnitTestCase
{
public function testAggressiveModelLoading()
{
Expand Down Expand Up @@ -92,21 +92,22 @@ public function testModelLoadingCacheInformation()
$this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingContact']));
}

public function testGetConnectionByTableName()
public function testGetConnectionByTableNameForTableWithOneModel()
{
$connectionBefore = Doctrine_Core::getConnectionByTableName('entity');
$connectionBefore = Doctrine_Core::getConnectionByTableName('account');

Doctrine_Manager::connection('sqlite::memory:', 'test_memory');
Doctrine_Manager::getInstance()->bindComponent('Entity', 'test_memory');
$this->openAdditionalConnection('sqlite::memory:', 'test_memory');

$connectionAfter = Doctrine_Core::getConnectionByTableName('entity');
Doctrine_Manager::getInstance()->bindComponent('Account', 'test_memory');

$connectionAfter = Doctrine_Core::getConnectionByTableName('account');

$this->assertEqual($connectionAfter->getName(), 'test_memory');

Doctrine_Manager::getInstance()->bindComponent('Entity', $connectionBefore->getName());
Doctrine_Manager::getInstance()->bindComponent('Account', $connectionBefore->getName());

$connectionAfter = Doctrine_Core::getConnectionByTableName('account');

$connectionAfter = Doctrine_Core::getConnectionByTableName('entity');

$this->assertEqual($connectionBefore->getName(), $connectionAfter->getName());
}
}
}
8 changes: 2 additions & 6 deletions tests/CliTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @since 1.0
* @version $Revision$
*/
class Doctrine_Cli_TestCase extends Doctrine_UnitTestCase
class Doctrine_Cli_TestCase extends UnitTestCase
{
/**
* @ignore
Expand Down Expand Up @@ -63,10 +63,6 @@ protected function getFixturesPath()
return $this->fixturesPath;
}

public function setUp() {}

public function tearDown() {}

public function testTheNameOfTheTaskBaseClassNameIsStoredInAClassConstant()
{
$this->assertFalse(is_null(constant('Doctrine_Cli::TASK_BASE_CLASS')));
Expand Down Expand Up @@ -446,4 +442,4 @@ protected function _run(array $args)
class Doctrine_Cli_TestCase_TestTask01 extends Doctrine_Task
{
public function execute() {}
}
}
5 changes: 4 additions & 1 deletion tests/Connection/CustomTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function testConnection()

class Doctrine_Connection_Test extends Doctrine_Connection_Common
{

/**
* @var string $driverName The name of this connection driver
*/
protected $driverName = 'Mock';
}

class Doctrine_Adapter_Test implements Doctrine_Adapter_Interface
Expand Down
46 changes: 37 additions & 9 deletions tests/DoctrineTest/Doctrine_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ class Doctrine_UnitTestCase extends UnitTestCase

protected $init = false;

/**
* @var Doctrine_Connection[]
*/
private $additionalConnections = array();

public function setUp()
{
parent::setUp();

if ( ! $this->init) {
$this->init();
}
if (isset($this->objTable)) {
$this->objTable->clear();
}

$this->init = true;
}

public function tearDown()
{
$this->closeAdditionalConnections();

parent::tearDown();
}

public function getName()
{
return $this->_name;
Expand Down Expand Up @@ -275,18 +301,20 @@ public function getDeclaration($type)
{
return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 1, 'fixed' => true));
}
public function setUp()

protected function openAdditionalConnection($adapter = null, $name = null)
{
if ( ! $this->init) {
$this->init();
}
if (isset($this->objTable)) {
$this->objTable->clear();
}
$connection = $this->manager->openConnection($adapter, $name);

$this->init = true;
$this->additionalConnections[] = $connection;

return $connection;
}

public function tearDown() {
private function closeAdditionalConnections()
{
foreach ($this->additionalConnections as $connection) {
$this->manager->closeConnection($connection);
}
}
}
Loading