1
0
mirror of synced 2025-01-31 20:41:44 +03:00

#1173 - test CS fixes, reduced clutter code, made method names more explicit

This commit is contained in:
Marco Pivetta 2014-11-11 12:37:16 +01:00
parent 511893e182
commit 2888791e5c

View File

@ -1,125 +1,113 @@
<?php <?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Tests\ORM\Functional; namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Tools\ToolsException; use Doctrine\ORM\Tools\ToolsException;
use Doctrine\Tests\OrmFunctionalTestCase;
class MergeSharedEntitiesTest extends \Doctrine\Tests\OrmFunctionalTestCase class MergeSharedEntitiesTest extends OrmFunctionalTestCase
{ {
/**
* {@inheritDoc}
*/
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
try { try {
$this->_schemaTool->createSchema( $this->_schemaTool->createSchema(array(
array( $this->_em->getClassMetadata(__NAMESPACE__ . '\MSEFile'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\MSEFile'), $this->_em->getClassMetadata(__NAMESPACE__ . '\MSEPicture'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\MSEPicture'), ));
)
);
} catch (ToolsException $ignored) { } catch (ToolsException $ignored) {
} }
} }
public function testMergeSharedNewEntities() public function testMergeSharedNewEntities()
{ {
$file = new MSEFile;
/** @var MSEPicture $picture */
$file = new MSEFile;
$picture = new MSEPicture; $picture = new MSEPicture;
$picture->file = $file;
$picture->file = $file;
$picture->otherFile = $file; $picture->otherFile = $file;
$em = $this->_em; $picture = $this->_em->merge($picture);
$picture = $em->merge($picture); $this->assertEquals($picture->file, $picture->otherFile, 'Identical entities must remain identical');
$this->assertEquals($picture->file, $picture->otherFile, "Identical entities must remain identical");
} }
public function testMergeSharedManagedEntities() public function testMergeSharedManagedEntities()
{ {
$file = new MSEFile;
/** @var MSEPicture $picture */
$file = new MSEFile;
$picture = new MSEPicture; $picture = new MSEPicture;
$picture->file = $file;
$picture->file = $file;
$picture->otherFile = $file; $picture->otherFile = $file;
$em = $this->_em; $this->_em->persist($file);
$em->persist($file); $this->_em->persist($picture);
$em->flush(); $this->_em->flush();
$em->clear(); $this->_em->clear();
$picture = $em->merge($picture); $picture = $this->_em->merge($picture);
$this->assertEquals($picture->file, $picture->otherFile, "Identical entities must remain identical"); $this->assertEquals($picture->file, $picture->otherFile, 'Identical entities must remain identical');
} }
public function testMergeSharedManagedEntitiesSerialize() public function testMergeSharedDetachedSerializedEntities()
{ {
$file = new MSEFile;
/** @var MSEPicture $picture */
$file = new MSEFile;
$picture = new MSEPicture; $picture = new MSEPicture;
$picture->file = $file;
$picture->file = $file;
$picture->otherFile = $file; $picture->otherFile = $file;
$serializedPicture = serialize($picture); $serializedPicture = serialize($picture);
$em = $this->_em; $this->_em->persist($file);
$em->persist($file); $this->_em->persist($picture);
$em->flush(); $this->_em->flush();
$em->clear(); $this->_em->clear();
$picture = unserialize($serializedPicture); $picture = $this->_em->merge(unserialize($serializedPicture));
$picture = $em->merge($picture);
$this->assertEquals($picture->file, $picture->otherFile, "Identical entities must remain identical"); $this->assertEquals($picture->file, $picture->otherFile, 'Identical entities must remain identical');
} }
} }
/** /** @Entity */
* @Entity
*/
class MSEPicture class MSEPicture
{ {
/** /** @Column(type="integer") @Id @GeneratedValue */
* @Column(name="picture_id", type="integer") public $id;
* @Id @GeneratedValue
*/
public $pictureId;
/** /** @ManyToOne(targetEntity="MSEFile", cascade={"merge"}) */
* @ManyToOne(targetEntity="MSEFile", cascade={"persist", "merge"})
* @JoinColumn(name="file_id", referencedColumnName="file_id")
*/
public $file; public $file;
/** /** @ManyToOne(targetEntity="MSEFile", cascade={"merge"}) */
* @ManyToOne(targetEntity="MSEFile", cascade={"persist", "merge"})
* @JoinColumn(name="other_file_id", referencedColumnName="file_id")
*/
public $otherFile; public $otherFile;
} }
/** /** @Entity */
* @Entity
*/
class MSEFile class MSEFile
{ {
/** /** @Column(type="integer") @Id @GeneratedValue(strategy="AUTO") */
* @Column(name="file_id", type="integer") public $id;
* @Id
* @GeneratedValue(strategy="AUTO")
*/
public $fileId;
} }