forked from doctrine/doctrine1
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding columns defined in actAs-templates to the docblock of the gene…
…rated model class.
- Loading branch information
Showing
3 changed files
with
250 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Ticket_gh110_TestRecord | ||
* | ||
* This class has been auto-generated by the Doctrine ORM Framework | ||
* | ||
* @property int $id Type: integer(4) | ||
* @property my_custom_type $created_at Type: my_custom_type | ||
* @property string $deleted_at Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) | ||
* | ||
* @method int getId() Type: integer(4) | ||
* @method my_custom_type getCreatedAt() Type: my_custom_type | ||
* @method string getDeletedAt() Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) | ||
* | ||
* @method Ticket_gh110_TestRecord setId(int $val) Type: integer(4) | ||
* @method Ticket_gh110_TestRecord setCreatedAt(my_custom_type $val) Type: my_custom_type | ||
* @method Ticket_gh110_TestRecord setDeletedAt(string $val) Type: timestamp, Timestamp in ISO-8601 format (YYYY-MM-DD HH:MI:SS) | ||
* | ||
* @package ##PACKAGE## | ||
* @subpackage ##SUBPACKAGE## | ||
* @author ##NAME## <##EMAIL##> | ||
* @version {{REPLACED}} | ||
*/ | ||
class Ticket_gh110_TestRecord extends Doctrine_Record | ||
{ | ||
public function setTableDefinition() | ||
{ | ||
$this->hasColumn('id', 'integer', 4, array( | ||
'type' => 'integer', | ||
'length' => 4, | ||
)); | ||
$this->hasColumn('created_at', 'my_custom_type', null, array( | ||
'type' => 'my_custom_type', | ||
'length' => '', | ||
)); | ||
} | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$softdelete0 = new Doctrine_Template_SoftDelete(array( | ||
)); | ||
$timestampable0 = new Doctrine_Template_Timestampable(array( | ||
'updated' => | ||
array( | ||
'disabled' => true, | ||
), | ||
'unknown_column' => | ||
array( | ||
), | ||
)); | ||
$unknownactas0 = new UnknownActAs(array( | ||
)); | ||
$gh110_template0 = new Doctrine_Template_gh110_Template(array( | ||
)); | ||
$gh110_invalid_template0 = new gh110_Invalid_Template(array( | ||
)); | ||
$this->actAs($softdelete0); | ||
$this->actAs($timestampable0); | ||
$this->actAs($unknownactas0); | ||
$this->actAs($gh110_template0); | ||
$this->actAs($gh110_invalid_template0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
class Doctrine_Ticket_gh110_TestCase extends Doctrine_UnitTestCase | ||
{ | ||
public function testAddActAsColumnsToDocBlock() | ||
{ | ||
$builder = new Doctrine_Import_Builder(); | ||
$class = $builder->buildDefinition( | ||
array( | ||
'className' => 'Ticket_gh110_TestRecord', | ||
'topLevelClassName' => 'Ticket_gh110_TestRecord', | ||
'is_base_class' => true, | ||
'columns' => array( | ||
'id' => array( | ||
'type' => 'integer', | ||
'length' => 4, | ||
), | ||
'my_custom_created_at' => array( | ||
'name' => 'created_at', | ||
'type' => 'my_custom_type', | ||
'length' => '', | ||
) | ||
), | ||
'actAs' => array( | ||
'SoftDelete' => array(), | ||
'Timestampable' => array( | ||
'updated' => array( | ||
'disabled' => true, | ||
), | ||
'unknown_column' => array() | ||
), | ||
'UnknownActAs' => array(), | ||
// This template brings an already defined column | ||
'gh110_Template' => array(), | ||
'gh110_Invalid_Template' => array(), | ||
) | ||
) | ||
); | ||
|
||
// We must replace the version as there is a timestamp in it. | ||
$class = preg_replace('/^.*@version.*$/m', ' * @version {{REPLACED}}', $class); | ||
// Can be used to update the snapshot. | ||
//file_put_contents(dirname(__FILE__) . '/gh110/Ticket_gh110_TestRecord.snapshot', $class); | ||
$this->assertEqual($class, file_get_contents(dirname(__FILE__) . '/gh110/Ticket_gh110_TestRecord.snapshot')); | ||
} | ||
} | ||
|
||
/** This is just a simple class without the required getOptions()-Method */ | ||
class gh110_Invalid_Template {} | ||
|
||
class Doctrine_Template_gh110_Template extends Doctrine_Template | ||
{ | ||
protected $_options = array( | ||
'created' => array( | ||
'name' => 'created_at', | ||
'alias' => null, | ||
'type' => 'timestamp', | ||
'format' => 'Y-m-d H:i:s', | ||
'disabled' => false, | ||
'expression' => false, | ||
'options' => array('notnull' => true) | ||
) | ||
); | ||
|
||
/** | ||
* Set table definition for Timestampable behavior | ||
* | ||
* @return void | ||
*/ | ||
public function setTableDefinition() | ||
{ | ||
if ( ! $this->_options['created']['disabled']) { | ||
$name = $this->_options['created']['name']; | ||
if ($this->_options['created']['alias']) { | ||
$name .= ' as ' . $this->_options['created']['alias']; | ||
} | ||
$this->hasColumn($name, $this->_options['created']['type'], null, $this->_options['created']['options']); | ||
} | ||
} | ||
} |