1
0
mirror of synced 2024-12-13 22:56:04 +03:00
doctrine2/tests/HydrateTestCase.php

109 lines
3.9 KiB
PHP
Raw Normal View History

2007-05-10 23:27:20 +04:00
<?php
/*
* $Id$
*
* 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.com>.
*/
/**
2007-05-13 03:00:25 +04:00
* Doctrine_Hydrate_TestCase
2007-05-10 23:27:20 +04:00
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
2007-05-13 03:00:25 +04:00
class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase
2007-05-10 23:27:20 +04:00
{
2007-05-11 01:31:35 +04:00
protected $testData1 = array(
array(
'e' => array('id' => 1, 'name' => 'zYne'),
'p' => array('id' => 1, 'phonenumber' => '123 123', 'user_id' => 1)
),
array(
'e' => array('id' => 2, 'name' => 'John'),
'p' => array('id' => 2, 'phonenumber' => '222 222', 'user_id' => 2)
),
2007-05-11 22:58:50 +04:00
array(
'e' => array('id' => 2, 'name' => 'John'),
'p' => array('id' => 3, 'phonenumber' => '343 343', 'user_id' => 2)
),
2007-05-11 01:31:35 +04:00
array(
'e' => array('id' => 3, 'name' => 'Arnold'),
2007-05-11 22:58:50 +04:00
'p' => array('id' => 4, 'phonenumber' => '333 333', 'user_id' => 3)
),
array(
'e' => array('id' => 4, 'name' => 'Arnold'),
'p' => array('id' => null, 'phonenumber' => null, 'user_id' => null)
2007-05-11 01:31:35 +04:00
)
);
public function prepareData()
{ }
2007-05-11 01:31:35 +04:00
public function testHydrateHooks()
2007-05-11 01:31:35 +04:00
{
$user = new User();
$user->getTable()->addRecordListener(new HydrationListener);
$user->name = 'zYne';
$user->save();
$this->conn->clear();
$user = Doctrine_Query::create()->from('User u')->fetchOne();
$this->assertEqual($user->name, 'ZYNE');
$this->assertEqual($user->password, 'DEFAULT PASS');
2007-05-11 01:31:35 +04:00
}
}
class HydrationListener extends Doctrine_Record_Listener
{
public function preHydrate(Doctrine_Event $event)
2007-05-11 01:31:35 +04:00
{
$data = $event->data;
$data['password'] = 'default pass';
$event->data = $data;
2007-05-11 01:31:35 +04:00
}
public function postHydrate(Doctrine_Event $event)
2007-05-10 23:27:20 +04:00
{
foreach ($event->data as $key => $value) {
$event->data[$key] = strtoupper($value);
}
2007-05-11 00:09:32 +04:00
}
}
2007-05-16 23:20:55 +04:00
class Doctrine_Hydrate_Mock extends Doctrine_Hydrate
2007-05-11 00:09:32 +04:00
{
protected $data;
public function setData($data)
{
$this->data = $data;
}
public function getQuery()
{
}
public function execute($params = array(), $hydrationMode = null)
2007-05-11 00:09:32 +04:00
{
return $this->data;
2007-05-10 23:49:05 +04:00
}
2007-05-10 23:27:20 +04:00
}