Refactored models.

This commit is contained in:
Dmitry Khomutov 2018-03-04 00:27:48 +07:00
commit 905d6d41d1
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
23 changed files with 368 additions and 581 deletions

View file

@ -4,9 +4,8 @@ namespace Tests\b8;
use b8\Form;
use b8\Config;
use PHPUnit\Framework\TestCase;
class FormTest extends TestCase
class FormTest extends \PHPUnit\Framework\TestCase
{
public function testFormBasics()
{
@ -17,7 +16,7 @@ class FormTest extends TestCase
self::assertTrue($f->getAction() == '/');
self::assertTrue($f->getMethod() == 'POST');
$config = new Config([
new Config([
'b8' => [
'view' => [
'path' => __DIR__ . '/data/view/'

View file

@ -1,43 +0,0 @@
<?php
namespace Tests\PHPCensor\Helper;
use Tests\PHPCensor\LocalizationTestCase;
class LangTest extends LocalizationTestCase
{
public function testSuccess()
{
self::assertTrue(true);
}
/**
* @return array
*/
public function localizationsProvider()
{
$directory = SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR;
$languages = [];
foreach(glob($directory . '*') as $file) {
$language = include($file);
$languages[$file] = [
$language
];
}
return $languages;
}
/**
* @dataProvider localizationsProvider
*/
/*public function testLocalizations(array $strings)
{
$directory = SRC_DIR . 'Languages' . DIRECTORY_SEPARATOR;
$en = include($directory . 'lang.en.php');
foreach ($en as $enIndex => $enString) {
self::assertArrayHasKey($enIndex, $strings);
}
}*/
}

View file

@ -1,24 +0,0 @@
<?php
namespace Tests\PHPCensor;
class LocalizationTestCase extends \PHPUnit\Framework\TestCase
{
/**
* Returns a string representation of the test case.
*
* @return string
*/
public function toString()
{
$class = new \ReflectionClass($this);
$buffer = sprintf(
'%s::%s',
$class->name,
$this->getName(false)
);
return $buffer . $this->getDataSetAsString(false);
}
}

View file

@ -2,6 +2,7 @@
namespace Tests\PHPCensor\Model;
use b8\Exception\HttpException\ValidationException;
use PHPCensor\Model\Build;
use PHPCensor\Model;
@ -12,15 +13,67 @@ use PHPCensor\Model;
*/
class BuildTest extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
}
public function testExecute_TestIsAValidModel()
public function testConstruct()
{
$build = new Build();
self::assertTrue($build instanceof \b8\Model);
self::assertTrue($build instanceof Model);
self::assertInstanceOf('PHPCensor\Model', $build);
self::assertInstanceOf('PHPCensor\Model\Build', $build);
$build = new Build([
'project_id' => 100,
'branch' => 'master',
]);
self::assertEquals([
'id' => null,
'project_id' => 100,
'commit_id' => null,
'status' => null,
'log' => null,
'branch' => 'master',
'tag' => null,
'create_date' => null,
'start_date' => null,
'finish_date' => null,
'committer_email' => null,
'commit_message' => null,
'extra' => null,
'environment' => null,
'source' => Build::SOURCE_UNKNOWN,
'user_id' => 0,
], $build->getDataArray());
try {
$build = new Build([
'project_id' => 101,
'branch' => 'dev',
'unknown' => 'unknown',
]);
} catch (\InvalidArgumentException $e) {
self::assertEquals(
'Model "PHPCensor\Model\Build" doesn\'t have field "unknown"',
$e->getMessage()
);
}
$build = new Build();
$build->setLog('log');
self::assertEquals('log', $build->getLog());
$build->setLog(null);
self::assertEquals(null, $build->getLog());
try {
$build->setLog([]);
} catch (ValidationException $e) {
self::assertEquals(
'Column "log" must be a string.',
$e->getMessage()
);
}
}
public function testExecute_TestBaseBuildDefaults()

View file

@ -15,7 +15,6 @@ class ProjectTest extends \PHPUnit\Framework\TestCase
public function testExecute_TestIsAValidModel()
{
$project = new Project();
self::assertTrue($project instanceof \b8\Model);
self::assertTrue($project instanceof Model);
}

View file

@ -139,7 +139,7 @@ class BuildServiceTest extends \PHPUnit\Framework\TestCase
{
$build = new Build();
$build->setId(1);
$build->setProject(101);
$build->setProjectId(101);
$build->setCommitId('abcde');
$build->setStatus(Build::STATUS_FAILED);
$build->setLog('Test');

View file

@ -94,7 +94,7 @@ class BuildStatusServiceTest extends \PHPUnit\Framework\TestCase
$project = $this->getProjectMock($config[$configId]['previousBuild'], $setProject);
$build->setProjectObject($project);
$build->setProjectId($project->getId());
return $build;
}