-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#111. Add BaseControllerTest, Fix GeneratorTraitTest, Change Json for…
… tests with exit, Add @dataProvider
- Loading branch information
1 parent
3bb6354
commit 3974b37
Showing
4 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<?php | ||
|
||
namespace rjapitest\unit\extensions; | ||
|
||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Routing\Route; | ||
use Modules\V2\Entities\Article; | ||
use Modules\V2\Http\Controllers\ArticleController; | ||
use ReflectionException; | ||
use rjapi\exceptions\AttributesException; | ||
use rjapi\extension\BaseController; | ||
use rjapitest\_data\ArticleFixture; | ||
use rjapitest\unit\TestCase; | ||
|
||
/** | ||
* This method is used not only here, but in constructor of BaseController | ||
* to retrieve headers etc | ||
* | ||
* @param array $json | ||
* @return Request | ||
*/ | ||
function request(array $json = []) | ||
{ | ||
$req = new Request(); | ||
$req->headers->set('Content-TYpe', 'application/json;ext=bulk'); | ||
$req->initialize([], [], [], [], [], [], json_encode($json)); | ||
|
||
return $req; | ||
} | ||
|
||
/** | ||
* Class BaseControllerTest | ||
* @package rjapitest\unit\extensions | ||
* | ||
* @property BaseController baseController | ||
*/ | ||
class BaseControllerTest extends TestCase | ||
{ | ||
private $baseController; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); // TODO: Change the autogenerated stub | ||
|
||
$_SERVER['HTTP_HOST'] = 'localhost'; | ||
|
||
$router = new Route(['POST', 'GET'], '', function () { | ||
}); | ||
$this->baseController = new ArticleController($router); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider articleProvider | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
* @param $data | ||
*/ | ||
public function it_creates_bulk($data) | ||
{ | ||
try { | ||
$this->baseController->createBulk(\rjapitest\unit\extensions\request($data)); | ||
} catch (AttributesException $e) { | ||
echo $e->getTraceAsString(); | ||
} | ||
|
||
$this->assertInstanceOf(BaseController::class, $this->baseController); | ||
} | ||
|
||
/** | ||
* @test | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function it_updates_bulk() | ||
{ | ||
/** @var Article $firstItem */ | ||
$firstItem = ArticleFixture::createAndGet(); | ||
$secondItem = ArticleFixture::createAndGet(); | ||
|
||
$data = [ | ||
'data' => [ | ||
[ | ||
'type' => 'article', | ||
'id' => $firstItem->id, | ||
'title' => $firstItem->title, | ||
'description' => $firstItem->description, | ||
'fake_attr' => 'attr', | ||
'url' => $firstItem->url, | ||
'show_in_top' => $firstItem->show_in_top, | ||
'topic_id' => $firstItem->topic_id, | ||
'rate' => $firstItem->rate, | ||
'date_posted' => $firstItem->date_posted, | ||
'time_to_live' => $firstItem->time_to_live, | ||
], | ||
[ | ||
'type' => 'article', | ||
'id' => $secondItem->id, | ||
'title' => $secondItem->title, | ||
'description' => $secondItem->description, | ||
'fake_attr' => 'attr', | ||
'url' => $secondItem->url, | ||
'show_in_top' => $secondItem->show_in_top, | ||
'topic_id' => $secondItem->topic_id, | ||
'rate' => $secondItem->rate, | ||
'date_posted' => $secondItem->date_posted, | ||
'time_to_live' => $secondItem->time_to_live, | ||
], | ||
], | ||
]; | ||
|
||
try { | ||
$this->baseController->updateBulk(\rjapitest\unit\extensions\request($data)); | ||
} catch (AttributesException $e) { | ||
echo $e->getTraceAsString(); | ||
} | ||
|
||
$this->assertInstanceOf(BaseController::class, $this->baseController); | ||
} | ||
|
||
/** | ||
* @test | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function it_deletes_bulk() | ||
{ | ||
$router = new Route(['DELETE'], '', function () { | ||
}); | ||
$this->baseController = new ArticleController($router); | ||
|
||
$firstItem = ArticleFixture::createAndGet(); | ||
$secondItem = ArticleFixture::createAndGet(); | ||
|
||
$data = [ | ||
'data' => [ | ||
[ | ||
'type' => 'article', | ||
'id' => $firstItem->id, | ||
], | ||
[ | ||
'type' => 'article', | ||
'id' => $secondItem->id, | ||
], | ||
], | ||
]; | ||
|
||
$this->baseController->deleteBulk(\rjapitest\unit\extensions\request($data)); | ||
$this->assertInstanceOf(BaseController::class, $this->baseController); | ||
} | ||
} |