Skip to content

Commit fc5630f

Browse files
committed
UnitTests implemented
1 parent 65978e0 commit fc5630f

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ composer.phar
33
composer.lock
44
apigen.phar
55
phpunit.phar
6-
build
6+
build
7+
*.sqlite
8+
.env

composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,26 @@
2121
"require": {
2222
"view-components/view-components": "*"
2323
},
24+
"require-dev": {
25+
"view-components/testing-helpers":"^1.1",
26+
"illuminate/database": "*"
27+
},
2428
"autoload": {
2529
"psr-4": {
2630
"ViewComponents\\Eloquent\\": "src/"
2731
}
2832
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"ViewComponents\\Eloquent\\Test\\Mock\\": "tests/mock/",
36+
"ViewComponents\\Eloquent\\Test\\": "tests/phpunit/"
37+
}
38+
},
39+
"scripts": {
40+
"post-install-cmd": [
41+
"ViewComponents\\Eloquent\\Installer::postComposerInstall"
42+
]
43+
},
2944
"support": {
3045
"email": "mail@vitaliy.in",
3146
"source": "https://github.com/view-components/eloquent-data-processing",

phpunit.xml.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="tests/bootstrap.php">
3+
<testsuites>
4+
<testsuite name="'view-components/eloquent-data-processing' test suite">
5+
<directory suffix=".php">./tests/phpunit</directory>
6+
</testsuite>
7+
</testsuites>
8+
</phpunit>

tests/bootstrap.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
require_once __DIR__ . '/../vendor/view-components/testing-helpers/bootstrap/bootstrap.php';
3+
use Illuminate\Database\Capsule\Manager as Capsule;
4+
$capsule = new Capsule;
5+
$capsule->addConnection([
6+
'driver' => 'sqlite',
7+
'database' => __DIR__ . '/../db.sqlite',
8+
'prefix' => '',
9+
]);
10+
$capsule->setAsGlobal();
11+
$capsule->bootEloquent();
12+
// set timezone for timestamps etc
13+
date_default_timezone_set('UTC');

tests/mock/TestUser.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace ViewComponents\Eloquent\Test\Mock;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class TestUser extends Model
8+
{
9+
10+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace ViewComponents\Eloquent\Test;
4+
5+
use ViewComponents\Eloquent\EloquentProcessingService;
6+
use ViewComponents\Eloquent\EloquentProcessorResolver;
7+
use ViewComponents\Eloquent\Test\Mock\TestUser;
8+
use ViewComponents\ViewComponents\Data\OperationCollection;
9+
use ViewComponents\ViewComponents\Test\Data\AbstractProcessingServiceTest;
10+
11+
require __DIR__ .'/../../vendor/view-components/view-components/tests/phpunit/Data/AbstractProcessingServiceTest.php';
12+
13+
class DbTableProcessingServiceTest extends AbstractProcessingServiceTest
14+
{
15+
public function setUp()
16+
{
17+
$this->data = (new TestUser())->newQuery();
18+
$this->operations = new OperationCollection();
19+
$this->service = new EloquentProcessingService(
20+
new EloquentProcessorResolver(),
21+
$this->operations,
22+
$this->data
23+
);
24+
$this->totalCount = (new TestUser())->newQuery()->get()->count();
25+
}
26+
}

0 commit comments

Comments
 (0)