Skip to content

Commit

Permalink
Rework structure of fixtures in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Oct 13, 2024
1 parent 070a238 commit 91158a0
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 24 deletions.
44 changes: 44 additions & 0 deletions src/Template/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ protected function setCreateMethod($name, $model, $type)
$lines[] = '$input = $this->input->post(null, true);';
$lines[] = '';
$lines[] = '$data = array();';

$lines = $this->setForeigns($lines, $model);

$lines[] = '';
$lines[] = 'if (! $input)';
$lines[] = '{';
Expand Down Expand Up @@ -544,6 +547,47 @@ protected function setEditMethod($name, $model, $type)
$this->addMethod($method);
}

/**
* @param string[] $lines
* @param string $model
*
* @return string[]
*/
protected function setForeigns($lines, $model)
{
// $items = array();

// foreach ($this->cols as $col)
// {
// if ($col->isForeignKey())
// {
// $items[] = $col;
// }
// }

// if (count($items) > 0)
// {
// $lines[] = '';
// }

// foreach ($items as $item)
// {
// $name = $item->getReferencedTable();
// $name = Inflector::plural($name);

// if ($this->type === self::TYPE_DOCTRINE)
// {
// $lines[] = '$data[\'' . $name . '\'] = $this->repo->dropdown(\'id\');';
// }
// else
// {
// $lines[] = '$data[\'' . $name . '\'] = $this->' . $model . '->get()->dropdown(\'id\');';
// }
// }

return $lines;
}

/**
* @param string $name
* @param string $model
Expand Down
File renamed without changes.
File renamed without changes.
58 changes: 34 additions & 24 deletions tests/PlateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function test_doctrine_controller()

$test->execute($input);

$expected = $this->getDoctrineCtrl();
$expected = $this->getDoctrineCtrl('Users');

$actual = $this->getActualCtrl('Users');

Expand All @@ -106,7 +106,7 @@ public function test_doctrine_model()

$test->execute($input);

$expected = $this->getDoctrineModel();
$expected = $this->getDoctrineModel('User');

$actual = $this->getActualModel('User');

Expand All @@ -125,7 +125,7 @@ public function test_doctrine_repository()

$test->execute($input);

$expected = $this->getDoctrineRepo();
$expected = $this->getDoctrineRepo('User');

$actual = $this->getActualRepo('User');

Expand Down Expand Up @@ -339,11 +339,11 @@ public function test_scaffold_on_doctrine()
$test->execute($input);

// Return the controller, model, and views --------
$route = $this->getDoctrineCtrl();
$route = $this->getDoctrineCtrl('Users');

$model = $this->getDoctrineModel();
$model = $this->getDoctrineModel('User');

$repo = $this->getDoctrineRepo();
$repo = $this->getDoctrineRepo('User');

$views = $this->getDoctrineView(self::VIEW_STYLED);

Expand Down Expand Up @@ -382,7 +382,7 @@ public function test_wildfire_controller()

$test->execute($input);

$expected = $this->getWildfireCtrl();
$expected = $this->getWildfireCtrl('Users');

$actual = $this->getActualCtrl('Users');

Expand All @@ -402,7 +402,7 @@ public function test_wildfire_model()

$test->execute($input);

$expected = $this->getWildfireModel();
$expected = $this->getWildfireModel('User');

$actual = $this->getActualModel('User');

Expand Down Expand Up @@ -610,27 +610,33 @@ protected function getActualView($name)
}

/**
* @param string $name
*
* @return string
*/
protected function getDoctrineCtrl()
protected function getDoctrineCtrl($name)
{
return $this->getTemplate('Doctrine/Controller');
return $this->getTemplate('Doctrine/Routes/' . $name);
}

/**
* @param string $name
*
* @return string
*/
protected function getDoctrineModel()
protected function getDoctrineModel($name)
{
return $this->getTemplate('Doctrine/Model');
return $this->getTemplate('Doctrine/Models/' . $name);
}

/**
* @param string $name
*
* @return string
*/
protected function getDoctrineRepo()
protected function getDoctrineRepo($name)
{
return $this->getTemplate('Doctrine/Repository');
return $this->getTemplate('Doctrine/Repos/' . $name);
}

/**
Expand All @@ -647,11 +653,11 @@ protected function getDoctrineView($type = self::VIEW_COMMON)
$name = 'Styled';
}

$create = $this->getTemplate('Doctrine/' . $name . '/CreateView');
$create = $this->getTemplate('Doctrine/Plates/' . $name . '/CreateView');

$edit = $this->getTemplate('Doctrine/' . $name . '/EditView');
$edit = $this->getTemplate('Doctrine/Plates/' . $name . '/EditView');

$index = $this->getTemplate('Doctrine/' . $name . '/IndexView');
$index = $this->getTemplate('Doctrine/Plates/' . $name . '/IndexView');

return $create . "\n" . $edit . "\n" . $index;
}
Expand Down Expand Up @@ -709,19 +715,23 @@ protected function getTemplate($name)
}

/**
* @param string $name
*
* @return string
*/
protected function getWildfireCtrl()
protected function getWildfireCtrl($name)
{
return $this->getTemplate('Wildfire/Controller');
return $this->getTemplate('Wildfire/Routes/' . $name);
}

/**
* @param string $name
*
* @return string
*/
protected function getWildfireModel()
protected function getWildfireModel($name)
{
return $this->getTemplate('Wildfire/Model');
return $this->getTemplate('Wildfire/Models/' . $name);
}

/**
Expand All @@ -738,11 +748,11 @@ protected function getWildfireView($type = self::VIEW_COMMON)
$name = 'Styled';
}

$create = $this->getTemplate('Wildfire/' . $name . '/CreateView');
$create = $this->getTemplate('Wildfire/Plates/' . $name . '/CreateView');

$edit = $this->getTemplate('Wildfire/' . $name . '/EditView');
$edit = $this->getTemplate('Wildfire/Plates/' . $name . '/EditView');

$index = $this->getTemplate('Wildfire/' . $name . '/IndexView');
$index = $this->getTemplate('Wildfire/Plates/' . $name . '/IndexView');

return $create . "\n" . $edit . "\n" . $index;
}
Expand Down

0 comments on commit 91158a0

Please sign in to comment.