Skip to content

Commit

Permalink
tests: test() with description
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 15, 2020
1 parent 1f457f6 commit fb8e92e
Show file tree
Hide file tree
Showing 61 changed files with 247 additions and 276 deletions.
2 changes: 1 addition & 1 deletion tests/Database.DI/DatabaseExtension.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


test(function () {
test('', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
database:
Expand Down
2 changes: 1 addition & 1 deletion tests/Database.DI/DatabaseExtension.multiple.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


test(function () {
test('', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
database:
Expand Down
10 changes: 5 additions & 5 deletions tests/Database/Connection.fetch.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");


test(function () use ($connection) { // fetch
test('fetch', function () use ($connection) {
$row = $connection->fetch('SELECT name, id FROM author WHERE id = ?', 11);
Assert::type(Nette\Database\Row::class, $row);
Assert::equal(Nette\Database\Row::from([
Expand All @@ -24,17 +24,17 @@ test(function () use ($connection) { // fetch
});


test(function () use ($connection) { // fetchField
test('fetchField', function () use ($connection) {
Assert::same('Jakub Vrana', $connection->fetchField('SELECT name FROM author ORDER BY id'));
});


test(function () use ($connection) { // fetchFields
test('fetchFields', function () use ($connection) {
Assert::same([11, 'Jakub Vrana'], $connection->fetchFields('SELECT id, name FROM author ORDER BY id'));
});


test(function () use ($connection) { // fetchPairs
test('fetchPairs', function () use ($connection) {
$pairs = $connection->fetchPairs('SELECT name, id FROM author WHERE id > ? ORDER BY id', 11);
Assert::same([
'David Grudl' => 12,
Expand All @@ -43,7 +43,7 @@ test(function () use ($connection) { // fetchPairs
});


test(function () use ($connection) { // fetchAll
test('fetchAll', function () use ($connection) {
$arr = $connection->fetchAll('SELECT name, id FROM author WHERE id < ? ORDER BY id', 13);
Assert::equal([
Nette\Database\Row::from(['name' => 'Jakub Vrana', 'id' => 11]),
Expand Down
8 changes: 4 additions & 4 deletions tests/Database/Connection.lazy.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


test(function () { // non lazy
test('non lazy', function () {
Assert::exception(function () {
$connection = new Nette\Database\Connection('dsn', 'user', 'password');
}, Nette\Database\DriverException::class, 'invalid data source name');
});


test(function () { // lazy
test('lazy', function () {
$connection = new Nette\Database\Connection('dsn', 'user', 'password', ['lazy' => true]);
$context = new Nette\Database\Context($connection, new Structure($connection, new DevNullStorage));
Assert::exception(function () use ($context) {
Expand All @@ -30,15 +30,15 @@ test(function () { // lazy
});


test(function () {
test('', function () {
$connection = new Nette\Database\Connection('dsn', 'user', 'password', ['lazy' => true]);
Assert::exception(function () use ($connection) {
$connection->quote('x');
}, Nette\Database\DriverException::class, 'invalid data source name');
});


test(function () { // connect & disconnect
test('connect & disconnect', function () {
$options = Tester\Environment::loadData() + ['user' => null, 'password' => null];
$connections = 1;

Expand Down
6 changes: 3 additions & 3 deletions tests/Database/Connection.query.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");


test(function () use ($connection) {
test('', function () use ($connection) {
$res = $connection->query('SELECT id FROM author WHERE id = ?', 11);
Assert::type(Nette\Database\ResultSet::class, $res);
Assert::same('SELECT id FROM author WHERE id = ?', $res->getQueryString());
Expand All @@ -23,14 +23,14 @@ test(function () use ($connection) {
});


test(function () use ($connection) {
test('', function () use ($connection) {
$res = $connection->query('SELECT id FROM author WHERE id = ? OR id = ?', 11, 12);
Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $res->getQueryString());
Assert::same([11, 12], $res->getParameters());
});


test(function () use ($connection) {
test('', function () use ($connection) {
$res = $connection->queryArgs('SELECT id FROM author WHERE id = ? OR id = ?', [11, 12]);
Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $res->getQueryString());
Assert::same([11, 12], $res->getParameters());
Expand Down
10 changes: 5 additions & 5 deletions tests/Database/Context.fetch.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");


test(function () use ($context) { // fetch
test('fetch', function () use ($context) {
$row = $context->fetch('SELECT name, id FROM author WHERE id = ?', 11);
Assert::type(Nette\Database\Row::class, $row);
Assert::equal(Nette\Database\Row::from([
Expand All @@ -24,17 +24,17 @@ test(function () use ($context) { // fetch
});


test(function () use ($context) { // fetchField
test('fetchField', function () use ($context) {
Assert::same('Jakub Vrana', $context->fetchField('SELECT name FROM author ORDER BY id'));
});


test(function () use ($context) { // fetchFields
test('fetchFields', function () use ($context) {
Assert::same([11, 'Jakub Vrana'], $context->fetchFields('SELECT id, name FROM author ORDER BY id'));
});


test(function () use ($context) { // fetchPairs
test('fetchPairs', function () use ($context) {
$pairs = $context->fetchPairs('SELECT name, id FROM author WHERE id > ? ORDER BY id', 11);
Assert::same([
'David Grudl' => 12,
Expand All @@ -43,7 +43,7 @@ test(function () use ($context) { // fetchPairs
});


test(function () use ($context) { // fetchAll
test('fetchAll', function () use ($context) {
$arr = $context->fetchAll('SELECT name, id FROM author WHERE id < ? ORDER BY id', 13);
Assert::equal([
Nette\Database\Row::from(['name' => 'Jakub Vrana', 'id' => 11]),
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/Context.query.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ require __DIR__ . '/connect.inc.php'; // create $connection
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");


test(function () use ($context) {
test('', function () use ($context) {
$res = $context->query('SELECT id FROM author WHERE id = ?', 11);
Assert::type(Nette\Database\ResultSet::class, $res);
Assert::same('SELECT id FROM author WHERE id = ?', $res->getQueryString());
Assert::same([11], $res->getParameters());
});


test(function () use ($context) {
test('', function () use ($context) {
$res = $context->query('SELECT id FROM author WHERE id = ? OR id = ?', 11, 12);
Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $res->getQueryString());
Assert::same([11, 12], $res->getParameters());
});


test(function () use ($context) {
test('', function () use ($context) {
$res = $context->queryArgs('SELECT id FROM author WHERE id = ? OR id = ?', [11, 12]);
Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $res->getQueryString());
Assert::same([11, 12], $res->getParameters());
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/Context.transaction.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");


test(function () use ($context) {
test('', function () use ($context) {
$context->beginTransaction();
$context->query('DELETE FROM book');
$context->rollBack();
Expand All @@ -23,7 +23,7 @@ test(function () use ($context) {
});


test(function () use ($context) {
test('', function () use ($context) {
$context->beginTransaction();
$context->query('DELETE FROM book');
$context->commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use Tester\Assert;
require __DIR__ . '/../../bootstrap.php';


// basic test
test(function () {
test('basic test', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([
'author_id' => 'authors',
Expand All @@ -26,8 +25,7 @@ test(function () {
Assert::same(['authors', 'translator_id'], $conventions->getBelongsToReference('books', 'translator'));
});

// basic test
test(function () {
test('basic test', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getBelongsToReference')->with('public.books')->andReturn([
'author_id' => 'public.authors',
Expand All @@ -40,8 +38,7 @@ test(function () {
Assert::same(['public.authors', 'translator_id'], $conventions->getBelongsToReference('public.books', 'translator'));
});

// tests order of table columns with foreign keys
test(function () {
test('tests order of table columns with foreign keys', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([
'translator_id' => 'authors',
Expand All @@ -54,8 +51,7 @@ test(function () {
});


// tests case insensivity
test(function () {
test('tests case insensivity', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([
'author_id' => 'authors',
Expand All @@ -68,8 +64,7 @@ test(function () {
});


// tests case insensivity and prefixes
test(function () {
test('tests case insensivity and prefixes', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getBelongsToReference')->with('nBooks')->andReturn([
'authorId' => 'nAuthors',
Expand All @@ -83,8 +78,7 @@ test(function () {
});


// tests rebuilt
test(function () {
test('tests rebuilt', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('isRebuilt')->andReturn(false);
$structure->shouldReceive('rebuild');
Expand All @@ -101,8 +95,7 @@ test(function () {
});


// tests already rebuilt structure
test(function () {
test('tests already rebuilt structure', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('isRebuilt')->andReturn(true);
$structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([])->once();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use Tester\Assert;
require __DIR__ . '/../../bootstrap.php';


// basic test singular
test(function () {
test('basic test singular', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getHasManyReference')->with('author')->andReturn([
'book' => ['author_id', 'translator_id'],
Expand Down Expand Up @@ -42,8 +41,7 @@ test(function () {
});


// basic test singular with schema
test(function () {
test('basic test singular with schema', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getHasManyReference')->with('public.author')->andReturn([
'public.book' => ['author_id', 'translator_id'],
Expand Down Expand Up @@ -86,8 +84,7 @@ test(function () {
});


// basic test plural
test(function () {
test('basic test plural', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getHasManyReference')->with('authors')->andReturn([
'books' => ['author_id', 'translator_id'],
Expand All @@ -110,8 +107,7 @@ test(function () {
});


// tests column match with source table
test(function () {
test('tests column match with source table', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getHasManyReference')->with('author')->andReturn([
'book' => ['author_id', 'tran_id'],
Expand All @@ -137,8 +133,7 @@ test(function () {
});


// tests case insensivity and prefixes
test(function () {
test('tests case insensivity and prefixes', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getHasManyReference')->with('nAuthors')->andReturn([
'nBooks' => ['authorId', 'translatorId'],
Expand All @@ -150,8 +145,7 @@ test(function () {
});


// tests rebuilt
test(function () {
test('tests rebuilt', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('isRebuilt')->andReturn(false);
$structure->shouldReceive('rebuild');
Expand All @@ -165,8 +159,7 @@ test(function () {
});


// tests already rebuilt structure
test(function () {
test('tests already rebuilt structure', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('isRebuilt')->andReturn(true);
$structure->shouldReceive('getHasManyReference')->with('author')->andReturn([])->once();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Tester\Assert;
require __DIR__ . '/../../bootstrap.php';


test(function () {
test('', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure->shouldReceive('getPrimaryKey')->with('books_x_tags')->andReturn(['book_id', 'tag_id']);

Expand Down
Loading

0 comments on commit fb8e92e

Please sign in to comment.