1
0
mirror of synced 2024-12-13 14:56:01 +03:00
doctrine2/tests_old/Ticket/741TestCase.php

81 lines
1.9 KiB
PHP
Raw Normal View History

2008-01-23 02:25:20 +03:00
<?php
class Doctrine_Ticket_741_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function prepareTables()
{
$this->tables = array('Parent741', 'Child741');
parent::prepareTables();
}
public function testTicket()
{
$moo = new Parent741();
$moo->amount = 1000;
$cow = new Child741();
$moo->Cows[] = $cow;
$cow->Moo = $moo;
$moo->save();
$this->assertEqual($moo->amount, 0);
}
}
class Parent741 extends Doctrine_Entity
2008-01-23 02:25:20 +03:00
{
public static function initMetadata($class)
2008-01-23 02:25:20 +03:00
{
$class->setColumn('id', 'integer', 4, array (
2008-01-23 02:25:20 +03:00
'primary' => true,
'autoincrement' => true,
'notnull' => true,
));
$class->setColumn('amount', 'integer');
$class->hasMany('Child741 as Cows', array('local' => 'id', 'foreign' => 'moo_id'));
2008-01-23 02:25:20 +03:00
}
}
class Child741 extends Doctrine_Entity
2008-01-23 02:25:20 +03:00
{
public static function initMetadata($class)
2008-01-23 02:25:20 +03:00
{
$class->setColumn('id', 'integer', 4, array (
2008-01-23 02:25:20 +03:00
'primary' => true,
'autoincrement' => true,
'notnull' => true,
));
$class->setColumn('moo_id', 'integer');
$class->hasOne('Parent741 as Moo', array('local' => 'moo_id', 'foreign' => 'id'));
2008-01-23 02:25:20 +03:00
}
public function postInsert($e)
{
//echo "State: ". $this->Moo->state() . " \t Amount: " . $this->Moo->amount . "\n";
$this->Moo->amount = 0;
//echo "State: ". $this->Moo->state() . " \t Amount: " . $this->Moo->amount . "\n";
$this->Moo->save();
//echo "State: ". $this->Moo->state() . " \t Amount: " . $this->Moo->amount . "\n";
$this->Moo->refresh();
//echo "State: ". $this->Moo->state() . " \t Amount: " . $this->Moo->amount . "\n";
/*
This outputs the following
State: 6 Amount: 1000
State: 6 Amount: 0
State: 6 Amount: 0
State: 3 Amount: 1000
*/
}
}