Skip to content

Commit

Permalink
Using separate directory for relation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phalcon committed Jul 6, 2013
1 parent b8c343e commit cab7c46
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 3 deletions.
4 changes: 2 additions & 2 deletions unit-tests/ModelsRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __destruct()
public function modelsAutoloader($className)
{
$className = str_replace('\\', DIRECTORY_SEPARATOR, $className);
if (file_exists('unit-tests/models/'.$className.'.php')) {
require 'unit-tests/models/'.$className.'.php';
if (file_exists('unit-tests/models/Relations/' . $className . '.php')) {
require 'unit-tests/models/Relations/' . $className . '.php';
}
}

Expand Down
33 changes: 33 additions & 0 deletions unit-tests/models/Relations/Deles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Deles
*
* Deles is "parts" in danish
*/
class Deles extends Phalcon\Mvc\Model
{

public function getSource()
{
return 'parts';
}

public function columnMap()
{
return array(
'id' => 'code',
'name' => 'theName',
);
}

public function initialize()
{
$this->hasMany('code', 'RobottersDeles', 'delesCode', array(
'foreignKey' => array(
'message' => 'Deles cannot be deleted because is referenced by a Robotter'
)
));
}

}
15 changes: 15 additions & 0 deletions unit-tests/models/Relations/Parts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class Parts extends Phalcon\Mvc\Model
{

public function initialize()
{
$this->hasMany('id', 'RobotsParts', 'parts_id', array(
'foreignKey' => array(
'message' => 'Parts cannot be deleted because is referenced by a Robot'
)
));
}

}
14 changes: 14 additions & 0 deletions unit-tests/models/Relations/Robots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class Robots extends Phalcon\Mvc\Model
{

public function initialize()
{
$this->hasMany('id', 'RobotsParts', 'robots_id', array(
'foreignKey' => true
));
$this->hasManyToMany('id', 'RobotsParts', 'robots_id', 'parts_id', 'Parts', 'id');
}

}
18 changes: 18 additions & 0 deletions unit-tests/models/Relations/RobotsParts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class RobotsParts extends Phalcon\Mvc\Model
{

public function initialize()
{
$this->belongsTo('parts_id', 'Parts', 'id', array(
'foreignKey' => true
));
$this->belongsTo('robots_id', 'Robots', 'id', array(
'foreignKey' => array(
'message' => 'The robot code does not exist'
)
));
}

}
33 changes: 33 additions & 0 deletions unit-tests/models/Relations/Robotters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Robotters
*
* "robotters" is robots in danish
*/
class Robotters extends Phalcon\Mvc\Model
{

public function getSource()
{
return 'robots';
}

public function columnMap()
{
return array(
'id' => 'code',
'name' => 'theName',
'type' => 'theType',
'year' => 'theYear'
);
}

public function initialize()
{
$this->hasMany('code', 'RobottersDeles', 'robottersCode', array(
'foreignKey' => true
));
}

}
39 changes: 39 additions & 0 deletions unit-tests/models/Relations/RobottersDeles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* RobottersDeles
*
* This model is an intermediate table for "Robotters" and "Deles"
*/
class RobottersDeles extends Phalcon\Mvc\Model
{

public function getSource()
{
return 'robots_parts';
}

public function columnMap()
{
return array(
'id' => 'code',
'robots_id' => 'robottersCode',
'parts_id' => 'delesCode',
);
}

public function initialize()
{

$this->belongsTo('delesCode', 'Deles', 'code', array(
'foreignKey' => true
));

$this->belongsTo('robottersCode', 'Robotters', 'code', array(
'foreignKey' => array(
'message' => 'The robotters code does not exist'
)
));
}

}
35 changes: 35 additions & 0 deletions unit-tests/models/Relations/Some/Deles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Some;

/**
* Deles
*
* Deles is "parts" in danish
*/
class Deles extends \Phalcon\Mvc\Model
{

public function getSource()
{
return 'parts';
}

public function columnMap()
{
return array(
'id' => 'code',
'name' => 'theName',
);
}

public function initialize()
{
$this->hasMany('code', 'Some\RobottersDeles', 'delesCode', array(
'foreignKey' => array(
'message' => 'Deles cannot be deleted because is referenced by a Robotter'
)
));
}

}
22 changes: 22 additions & 0 deletions unit-tests/models/Relations/Some/Parts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Some;

class Parts extends \Phalcon\Mvc\Model
{

public function getSource()
{
return 'parts';
}

public function initialize()
{
$this->hasMany('id', 'RobotsParts', 'parts_id', array(
'foreignKey' => array(
'message' => 'Parts cannot be deleted because is referenced by a Robot'
)
));
}

}
52 changes: 52 additions & 0 deletions unit-tests/models/Relations/Some/Products.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Some;

use Phalcon\Db\Column;
use Phalcon\Mvc\Model\MetaData;

class Products extends \Phalcon\Mvc\Model
{

public function getSource(){
return 'le_products';
}

public function metaData()
{
return array(
MetaData::MODELS_ATTRIBUTES => array(
'id', 'name', 'type', 'price'
),
MetaData::MODELS_PRIMARY_KEY => array(
'id'
),
MetaData::MODELS_NON_PRIMARY_KEY => array(
'name', 'type', 'price'
),
MetaData::MODELS_NOT_NULL => array(
'id', 'name', 'type', 'price'
),
MetaData::MODELS_DATA_TYPES => array(
'id' => Column::TYPE_INTEGER,
'name' => Column::TYPE_VARCHAR,
'type' => Column::TYPE_VARCHAR,
'price' => Column::TYPE_INTEGER
),
MetaData::MODELS_DATA_TYPES_NUMERIC => array(
'id' => true,
'price' => true,
),
MetaData::MODELS_IDENTITY_COLUMN => 'id',
MetaData::MODELS_DATA_TYPES_BIND => array(
'id' => Column::BIND_PARAM_INT,
'name' => Column::BIND_PARAM_STR,
'type' => Column::BIND_PARAM_STR,
'price' => Column::BIND_PARAM_INT,
),
MetaData::MODELS_AUTOMATIC_DEFAULT_INSERT => array(),
MetaData::MODELS_AUTOMATIC_DEFAULT_UPDATE => array()
);
}

}
25 changes: 25 additions & 0 deletions unit-tests/models/Relations/Some/Robots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Some;

class Robots extends \Phalcon\Mvc\Model
{

public function getSource()
{
return 'robots';
}

public function initialize()
{
$this->hasMany('id', 'Some\RobotsParts', 'robots_id', array(
'foreignKey' => true
));
}

public function getRobotsParts($arguments=null)
{
return $this->getRelated('Some\RobotsParts', $arguments);
}

}
25 changes: 25 additions & 0 deletions unit-tests/models/Relations/Some/RobotsParts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Some;

class RobotsParts extends \Phalcon\Mvc\Model
{

public function getSource()
{
return 'robots_parts';
}

public function initialize()
{
$this->belongsTo('parts_id', 'Parts', 'id', array(
'foreignKey' => true
));
$this->belongsTo('robots_id', 'Robots', 'id', array(
'foreignKey' => array(
'message' => 'The robot code does not exist'
)
));
}

}
40 changes: 40 additions & 0 deletions unit-tests/models/Relations/Some/Robotters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Some;

/**
* Robotters
*
* "robotters" is robots in danish
*/
class Robotters extends \Phalcon\Mvc\Model
{

public function getSource()
{
return 'robots';
}

public function columnMap()
{
return array(
'id' => 'code',
'name' => 'theName',
'type' => 'theType',
'year' => 'theYear'
);
}

public function initialize()
{
$this->hasMany('code', 'Some\RobottersDeles', 'robottersCode', array(
'foreignKey' => true
));
}

public function getRobottersDeles($arguments=null)
{
return $this->getRelated('Some\RobottersDeles', $arguments);
}

}
Loading

0 comments on commit cab7c46

Please sign in to comment.