mirror of
https://github.com/moparisthebest/wallabag
synced 2025-01-31 07:10:30 -05:00
Use fixtures for tests
This commit is contained in:
parent
43a934d560
commit
00ac1a58be
@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Poche\Tests\Functionals;
|
namespace Poche\Tests\Functionals;
|
||||||
|
use Poche\Tests\Functionals\Fixtures;
|
||||||
|
|
||||||
class ApiTest extends PocheWebTestCase
|
class ApiTest extends PocheWebTestCase
|
||||||
{
|
{
|
||||||
public function testGetEntries()
|
public function testEmptyGetEntries()
|
||||||
{
|
{
|
||||||
$client = $this->createClient();
|
$client = $this->createClient();
|
||||||
$crawler = $client->request('GET', '/api/entries');
|
$crawler = $client->request('GET', '/api/entries');
|
||||||
@ -18,6 +19,33 @@ class ApiTest extends PocheWebTestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertTrue($client->getResponse()->getContent() == '[]');
|
$this->assertEquals($client->getResponse()->getContent(), '[]');
|
||||||
|
|
||||||
|
//Load some entries
|
||||||
|
Fixtures::loadEntries($this->app['db']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetEntries()
|
||||||
|
{
|
||||||
|
|
||||||
|
//Load some entries
|
||||||
|
Fixtures::loadEntries($this->app['db']);
|
||||||
|
|
||||||
|
$client = $this->createClient();
|
||||||
|
$crawler = $client->request('GET', '/api/entries');
|
||||||
|
|
||||||
|
$this->assertTrue($client->getResponse()->isOk());
|
||||||
|
|
||||||
|
// Assert that the "Content-Type" header is "application/json"
|
||||||
|
$this->assertTrue(
|
||||||
|
$client->getResponse()->headers->contains(
|
||||||
|
'Content-Type',
|
||||||
|
'application/json'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($client->getResponse()->getContent(),'{"id":"1","url":"http:\/\/deboutlesgens.com\/blog\/le-courage-de-vivre-consciemment\/","title":"Le courage de vivre consciemment","content":"Test content","updated":null,"status":null,"bookmark":"0","fetched":"1","user_id":"1"}');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
tests/functionals/Fixtures.php
Normal file
17
tests/functionals/Fixtures.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Poche\Tests\Functionals;
|
||||||
|
|
||||||
|
class Fixtures
|
||||||
|
{
|
||||||
|
public static function loadUsers($db) {
|
||||||
|
|
||||||
|
$db->query("INSERT INTO users (id, username) values (1, 'poche_test');");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function loadEntries($db) {
|
||||||
|
|
||||||
|
$db->query("INSERT INTO entries (id, url, title, content, user_id) values (1, 'http://deboutlesgens.com/blog/le-courage-de-vivre-consciemment/', 'Le courage de vivre consciemment','Test content', 1);");
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Poche\Tests\Functionals;
|
namespace Poche\Tests\Functionals;
|
||||||
|
|
||||||
|
use Poche\Tests\Functionals\Fixtures;
|
||||||
|
|
||||||
use Silex\WebTestCase;
|
use Silex\WebTestCase;
|
||||||
|
|
||||||
use Poche\Schema;
|
use Poche\Schema;
|
||||||
|
|
||||||
class PocheWebTestCase extends WebTestCase
|
class PocheWebTestCase extends WebTestCase
|
||||||
{
|
{
|
||||||
|
protected $app;
|
||||||
|
|
||||||
public function createApplication()
|
public function createApplication()
|
||||||
{
|
{
|
||||||
require __DIR__.'/../../app/app.php';
|
require __DIR__.'/../../app/app.php';
|
||||||
@ -22,6 +26,10 @@ class PocheWebTestCase extends WebTestCase
|
|||||||
Schema::dropTables($app['db']);
|
Schema::dropTables($app['db']);
|
||||||
Schema::createTables($app['db']);
|
Schema::createTables($app['db']);
|
||||||
|
|
||||||
|
Fixtures::loadUsers($app['db']);
|
||||||
|
|
||||||
|
$this->app = $app;
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
require __DIR__.'/../../vendor/autoload.php';
|
require __DIR__.'/../../vendor/autoload.php';
|
||||||
|
require __DIR__.'/Fixtures.php';
|
||||||
require __DIR__.'/PocheWebTestCase.php';
|
require __DIR__.'/PocheWebTestCase.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user