Skip to content
Snippets Groups Projects
Commit 245b7c40 authored by xamgore's avatar xamgore
Browse files

Unit test for Model_Discipline class

parent 1f4dc733
Branches
Tags
No related merge requests found
...@@ -2,5 +2,105 @@ ...@@ -2,5 +2,105 @@
class Model_Discipline_Test extends PHPUnit_Framework_TestCase class Model_Discipline_Test extends PHPUnit_Framework_TestCase
{ {
/**
* @test
* @dataProvider incorrectArgumentsProvider
* @expectedException InvalidArgumentException
*/
public function createWithIncorrectArguments($name, $value) {
Model_Discipline::make()->fromSet([$name => $value]);
echo "createWithIncorrectArguments($name, $value)\n";
}
public function incorrectArgumentsProvider() {
return [
# 0
['author', 0],
['author', -1],
['faculty', 0],
['faculty', -1],
['grade', 0],
# 5
['grade', -1],
['labs', -1],
['practice', -1],
['lectures', -1],
['semester', 0],
# 10
['semester', -1],
['type', 'i love php'],
['type', ''],
['type', 0],
['type', -1],
# 15
['type', null],
['subject', 0],
['subject', -1],
];
}
/**
* @test
* @expectedException InvalidArgumentException
* @dataProvider notCompleteDataProvider
*/
public function passNotAllArgumentsToCreateDiscipline($data) {
Model_Discipline::make()->fromSet($data)->create()->delete();
printf("%s(%s)\n", __METHOD__, json_encode($data, JSON_PRETTY_PRINT));
}
public function notCompleteDataProvider() {
$data = $this->correctRawDataProvider();
foreach ($data as $arguments) {
foreach ($arguments as $raw) {
foreach ($raw as $name => $value) {
// removes one of the required fields
$copy = $data;
unset($copy[$name]);
yield $copy;
}
}
}
}
public function correctRawDataProvider() {
return [
# one function call
[
# one argument
[
'author' => 1,
'faculty' => 1,
'grade' => 1,
'lectures' => 0,
'labs' => 0,
'practice' => 0,
'semester' => 1,
'type' => Model_Discipline::CREDIT,
'subject' => 1,
]
]
];
}
/** @test */
public function checkNonExistingDiscipline() {
$this->assertFalse(Model_Discipline::load(PHP_INT_MAX)->exists());
}
/**
* @test
* @dataProvider correctRawDataProvider
*/
public function createDisciplineAndCheckExistence($data) {
$builder = Model_Discipline::make()->fromSet($data);
$discipline = $builder->create();
$this->assertTrue($discipline->exists());
$discipline->delete();
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment