2008-02-14 23:20:35 +03:00
|
|
|
<?php
|
2008-02-15 03:57:34 +03:00
|
|
|
/*
|
|
|
|
* $Id: Doctrine.php 3754 2008-02-13 10:53:07Z romanb $
|
|
|
|
*
|
|
|
|
* 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 LGPL. For more information, see
|
|
|
|
* <http://www.phpdoctrine.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-02-16 22:37:51 +03:00
|
|
|
* Testcase for basic accessor/mutator functionality.
|
2008-02-15 03:57:34 +03:00
|
|
|
*
|
|
|
|
* @package Doctrine
|
|
|
|
* @author Bjarte Stien Karlsen <doctrine@bjartek.org>
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
2008-02-22 21:11:35 +03:00
|
|
|
* @link www.phpdoctrine.org
|
2008-02-15 03:57:34 +03:00
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision: 3754 $
|
|
|
|
*/
|
2008-02-14 23:20:35 +03:00
|
|
|
require_once 'lib/DoctrineTestInit.php';
|
|
|
|
|
2008-02-16 22:37:51 +03:00
|
|
|
class AccessStub extends Doctrine_Access {}
|
|
|
|
|
2008-02-14 23:20:35 +03:00
|
|
|
class Orm_Component_AccessTest extends Doctrine_OrmTestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2008-05-17 16:22:24 +04:00
|
|
|
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
|
2008-02-14 23:20:35 +03:00
|
|
|
$this->user = new ForumUser();
|
|
|
|
}
|
|
|
|
|
2008-03-05 14:24:33 +03:00
|
|
|
/*public function testAccessorOverridePerformance() {
|
2008-02-24 01:04:39 +03:00
|
|
|
$this->user->username;
|
|
|
|
$start = microtime(true);
|
|
|
|
for ($i = 0; $i < 1; $i++) {
|
|
|
|
$this->user->username;
|
|
|
|
}
|
|
|
|
$end = microtime(true);
|
|
|
|
echo ($end - $start) . " seconds" . PHP_EOL;
|
2008-03-05 14:24:33 +03:00
|
|
|
}*/
|
2008-02-24 01:04:39 +03:00
|
|
|
|
2008-02-14 23:20:35 +03:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2008-05-17 16:22:24 +04:00
|
|
|
public function shouldMarkEmptyFieldAsNotSetOnNewRecord()
|
2008-02-14 23:20:35 +03:00
|
|
|
{
|
2008-05-17 16:22:24 +04:00
|
|
|
$this->assertFalse(isset($this->user->username));
|
|
|
|
$this->assertFalse(isset($this->user['username']));
|
2008-02-14 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldMarkNonExistantFieldAsNotSetOnNewRecord()
|
|
|
|
{
|
|
|
|
$this->assertFalse(isset($this->user->rat));
|
|
|
|
$this->assertFalse(isset($this->user['rat']));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldSetSingleValueInRecord()
|
|
|
|
{
|
2008-02-16 22:37:51 +03:00
|
|
|
$this->user->username = 'meus';
|
2008-02-14 23:20:35 +03:00
|
|
|
$this->assertEquals('meus', $this->user->username);
|
|
|
|
$this->assertEquals('meus', $this->user['username']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldSetSingleValueInRecordWithOffset()
|
|
|
|
{
|
|
|
|
$this->user['username'] ='meus';
|
|
|
|
$this->assertEquals('meus', $this->user->username);
|
|
|
|
$this->assertEquals('meus', $this->user['username']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldSetArrayOfValusInRecord()
|
|
|
|
{
|
|
|
|
$this->user->setArray(array(
|
|
|
|
'username' => 'meus',
|
|
|
|
'id' => 22));
|
|
|
|
|
|
|
|
$this->assertEquals('meus', $this->user->username);
|
|
|
|
$this->assertEquals('meus', $this->user['username']);
|
|
|
|
|
|
|
|
$this->assertEquals(22, $this->user->id);
|
|
|
|
$this->assertEquals(22, $this->user['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2008-05-17 16:22:24 +04:00
|
|
|
* @expectedException Doctrine_Entity_Exception
|
2008-02-14 23:20:35 +03:00
|
|
|
*/
|
|
|
|
public function shouldNotBeAbleToSetNonExistantField()
|
|
|
|
{
|
2008-02-16 22:37:51 +03:00
|
|
|
$this->user->rat = 'meus';
|
2008-02-14 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2008-05-17 16:22:24 +04:00
|
|
|
* @expectedException Doctrine_Entity_Exception
|
2008-02-14 23:20:35 +03:00
|
|
|
*/
|
|
|
|
public function shouldNotBeAbleToSetNonExistantFieldWithOffset()
|
|
|
|
{
|
2008-02-16 22:37:51 +03:00
|
|
|
$this->user['rat'] = 'meus';
|
2008-02-14 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2008-05-17 16:22:24 +04:00
|
|
|
* @expectedException Doctrine_Entity_Exception
|
2008-02-14 23:20:35 +03:00
|
|
|
*/
|
|
|
|
public function shouldNotBeAbleToSetNonExistantFieldAsPartInSetArray()
|
|
|
|
{
|
|
|
|
$this->user->setArray(array(
|
|
|
|
'rat' => 'meus',
|
2008-02-16 22:37:51 +03:00
|
|
|
'id' => 22));
|
2008-02-14 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function newCollectionShouldBeEmpty()
|
|
|
|
{
|
|
|
|
$col = new Doctrine_Collection('ForumUser');
|
|
|
|
$this->assertEquals(0, count($col));
|
|
|
|
$this->assertFalse(isset($coll[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function shouldBeAbleToUnsetWithOffsetFromCollection()
|
|
|
|
{
|
|
|
|
$col = new Doctrine_Collection('ForumUser');
|
|
|
|
$col[0] = new ForumUser();
|
|
|
|
$this->assertTrue(isset($col[0]));
|
|
|
|
unset($col[0]);
|
|
|
|
$this->assertFalse(isset($col[0]));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function shouldBeAbleToUnsetFromCollection()
|
|
|
|
{
|
|
|
|
$col = new Doctrine_Collection('ForumUser');
|
|
|
|
$col->test = new ForumUser();
|
|
|
|
$this->assertTrue(isset($col->test));
|
|
|
|
unset($col->test);
|
|
|
|
$this->assertFalse(isset($col->test));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @test
|
|
|
|
* @expectedException Doctrine_Exception
|
|
|
|
*/
|
|
|
|
public function shouldNotBeAbleToSetNullFieldInRecord()
|
|
|
|
{
|
|
|
|
$this->user->offsetSet(null, 'test');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-02-15 00:14:47 +03:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @expectedException Doctrine_Exception
|
|
|
|
*/
|
|
|
|
public function shouldNotBeAbleToUseContainsWhenNotImplemented()
|
|
|
|
{
|
|
|
|
$stub = new AccessStub();
|
|
|
|
isset($stub['foo']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @expectedException Doctrine_Exception
|
|
|
|
*/
|
|
|
|
public function shouldNotBeAbleToUseSetWhenNotImplemented()
|
|
|
|
{
|
|
|
|
$stub = new AccessStub();
|
|
|
|
$stub['foo'] = 'foo';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @expectedException Doctrine_Exception
|
|
|
|
*/
|
|
|
|
public function shouldNotBeAbleToUseUnsetWhenNotImplemented()
|
|
|
|
{
|
|
|
|
$stub = new AccessStub();
|
|
|
|
unset($stub['foo']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @expectedException Doctrine_Exception
|
|
|
|
*/
|
|
|
|
public function shouldNotBeAbleToUseGetWhenNotImplemented()
|
|
|
|
{
|
|
|
|
$stub = new AccessStub();
|
|
|
|
$stub['foo'];
|
|
|
|
}
|
2008-02-14 23:20:35 +03:00
|
|
|
}
|