Included vendor/ to the project
This commit is contained in:
105
vendor/phpunit/dbunit/tests/Operation/OperationsMySQLTest.php
vendored
Normal file
105
vendor/phpunit/dbunit/tests/Operation/OperationsMySQLTest.php
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of DbUnit.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use PHPUnit\DbUnit\Database\DefaultConnection;
|
||||
use PHPUnit\DbUnit\DataSet\CompositeDataSet;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTable;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata;
|
||||
use PHPUnit\DbUnit\DataSet\FlatXmlDataSet;
|
||||
use PHPUnit\DbUnit\Operation\Truncate;
|
||||
use PHPUnit\DbUnit\TestCase;
|
||||
|
||||
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'DatabaseTestUtility.php';
|
||||
|
||||
class Extensions_Database_Operation_OperationsMySQLTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!extension_loaded('pdo_mysql')) {
|
||||
$this->markTestSkipped('pdo_mysql is required to run this test.');
|
||||
}
|
||||
|
||||
if (!defined('PHPUNIT_TESTSUITE_EXTENSION_DATABASE_MYSQL_DSN')) {
|
||||
$this->markTestSkipped('No MySQL server configured for this test.');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
{
|
||||
return new DefaultConnection(DBUnitTestUtility::getMySQLDB(), 'mysql');
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/OperationsMySQLTestFixture.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Truncate::execute
|
||||
*/
|
||||
public function testTruncate()
|
||||
{
|
||||
$truncateOperation = new Truncate();
|
||||
$truncateOperation->execute($this->getConnection(), $this->getDataSet());
|
||||
|
||||
$expectedDataSet = new DefaultDataSet([
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table1',
|
||||
['table1_id', 'column1', 'column2', 'column3', 'column4'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table2',
|
||||
['table2_id', 'table1_id', 'column5', 'column6', 'column7', 'column8'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table3',
|
||||
['table3_id', 'table2_id', 'column9', 'column10', 'column11', 'column12'])
|
||||
),
|
||||
]);
|
||||
|
||||
$this->assertDataSetsEqual($expectedDataSet, $this->getConnection()->createDataSet());
|
||||
}
|
||||
|
||||
public function getCompositeDataSet()
|
||||
{
|
||||
$compositeDataset = new CompositeDataSet();
|
||||
|
||||
$dataset = $this->createXMLDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/TruncateCompositeTest.xml');
|
||||
$compositeDataset->addDataSet($dataset);
|
||||
|
||||
return $compositeDataset;
|
||||
}
|
||||
|
||||
public function testTruncateComposite()
|
||||
{
|
||||
$truncateOperation = new Truncate();
|
||||
$truncateOperation->execute($this->getConnection(), $this->getCompositeDataSet());
|
||||
|
||||
$expectedDataSet = new DefaultDataSet([
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table1',
|
||||
['table1_id', 'column1', 'column2', 'column3', 'column4'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table2',
|
||||
['table2_id', 'table1_id', 'column5', 'column6', 'column7', 'column8'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table3',
|
||||
['table3_id', 'table2_id', 'column9', 'column10', 'column11', 'column12'])
|
||||
),
|
||||
]);
|
||||
|
||||
$this->assertDataSetsEqual($expectedDataSet, $this->getConnection()->createDataSet());
|
||||
}
|
||||
}
|
||||
147
vendor/phpunit/dbunit/tests/Operation/OperationsTest.php
vendored
Normal file
147
vendor/phpunit/dbunit/tests/Operation/OperationsTest.php
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of DbUnit.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use PHPUnit\DbUnit\Database\DefaultConnection;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTable;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata;
|
||||
use PHPUnit\DbUnit\DataSet\FlatXmlDataSet;
|
||||
use PHPUnit\DbUnit\Operation\Delete;
|
||||
use PHPUnit\DbUnit\Operation\DeleteAll;
|
||||
use PHPUnit\DbUnit\Operation\Insert;
|
||||
use PHPUnit\DbUnit\Operation\Update;
|
||||
use PHPUnit\DbUnit\Operation\Truncate;
|
||||
use PHPUnit\DbUnit\Operation\Replace;
|
||||
use PHPUnit\DbUnit\TestCase;
|
||||
|
||||
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'DatabaseTestUtility.php';
|
||||
|
||||
class Extensions_Database_Operation_OperationsTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!extension_loaded('pdo_sqlite')) {
|
||||
$this->markTestSkipped('PDO/SQLite is required to run this test.');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
{
|
||||
return new DefaultConnection(DBUnitTestUtility::getSQLiteMemoryDB(), 'sqlite');
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/OperationsTestFixture.xml');
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$deleteOperation = new Delete();
|
||||
|
||||
$deleteOperation->execute($this->getConnection(), new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/DeleteOperationTest.xml'));
|
||||
|
||||
$this->assertDataSetsEqual(new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/DeleteOperationResult.xml'), $this->getConnection()->createDataSet());
|
||||
}
|
||||
|
||||
public function testDeleteAll()
|
||||
{
|
||||
$deleteAllOperation = new DeleteAll();
|
||||
|
||||
$deleteAllOperation->execute($this->getConnection(), new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/DeleteAllOperationTest.xml'));
|
||||
|
||||
$expectedDataSet = new DefaultDataSet([
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table1',
|
||||
['table1_id', 'column1', 'column2', 'column3', 'column4'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table2',
|
||||
['table2_id', 'column5', 'column6', 'column7', 'column8'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table3',
|
||||
['table3_id', 'column9', 'column10', 'column11', 'column12'])
|
||||
),
|
||||
]);
|
||||
|
||||
$this->assertDataSetsEqual($expectedDataSet, $this->getConnection()->createDataSet());
|
||||
}
|
||||
|
||||
public function testTruncate()
|
||||
{
|
||||
$truncateOperation = new Truncate();
|
||||
|
||||
$truncateOperation->execute($this->getConnection(), new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/DeleteAllOperationTest.xml'));
|
||||
|
||||
$expectedDataSet = new DefaultDataSet([
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table1',
|
||||
['table1_id', 'column1', 'column2', 'column3', 'column4'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table2',
|
||||
['table2_id', 'column5', 'column6', 'column7', 'column8'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table3',
|
||||
['table3_id', 'column9', 'column10', 'column11', 'column12'])
|
||||
),
|
||||
]);
|
||||
|
||||
$this->assertDataSetsEqual($expectedDataSet, $this->getConnection()->createDataSet());
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$insertOperation = new Insert();
|
||||
|
||||
$insertOperation->execute($this->getConnection(), new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/InsertOperationTest.xml'));
|
||||
|
||||
$this->assertDataSetsEqual(new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/InsertOperationResult.xml'), $this->getConnection()->createDataSet());
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$updateOperation = new Update();
|
||||
|
||||
$updateOperation->execute($this->getConnection(), new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/UpdateOperationTest.xml'));
|
||||
|
||||
$this->assertDataSetsEqual(new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/UpdateOperationResult.xml'), $this->getConnection()->createDataSet());
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$replaceOperation = new Replace();
|
||||
|
||||
$replaceOperation->execute($this->getConnection(), new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/ReplaceOperationTest.xml'));
|
||||
|
||||
$this->assertDataSetsEqual(new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/ReplaceOperationResult.xml'), $this->getConnection()->createDataSet());
|
||||
}
|
||||
|
||||
public function testInsertEmptyTable()
|
||||
{
|
||||
$insertOperation = new Insert();
|
||||
|
||||
$insertOperation->execute($this->getConnection(), new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/EmptyTableInsertTest.xml'));
|
||||
|
||||
$this->assertDataSetsEqual(new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/EmptyTableInsertResult.xml'), $this->getConnection()->createDataSet());
|
||||
}
|
||||
public function testInsertAllEmptyTables()
|
||||
{
|
||||
$insertOperation = new Insert();
|
||||
|
||||
$insertOperation->execute($this->getConnection(), new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/AllEmptyTableInsertTest.xml'));
|
||||
|
||||
$this->assertDataSetsEqual(new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/AllEmptyTableInsertResult.xml'), $this->getConnection()->createDataSet());
|
||||
}
|
||||
}
|
||||
174
vendor/phpunit/dbunit/tests/Operation/RowBasedTest.php
vendored
Normal file
174
vendor/phpunit/dbunit/tests/Operation/RowBasedTest.php
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of DbUnit.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use PHPUnit\DbUnit\Database\DefaultConnection;
|
||||
use PHPUnit\DbUnit\Database\Connection;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTable;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata;
|
||||
use PHPUnit\DbUnit\DataSet\FlatXmlDataSet;
|
||||
use PHPUnit\DbUnit\DataSet\ITable;
|
||||
use PHPUnit\DbUnit\DataSet\ITableMetadata;
|
||||
use PHPUnit\DbUnit\Operation\RowBased;
|
||||
use PHPUnit\DbUnit\TestCase;
|
||||
|
||||
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'DatabaseTestUtility.php';
|
||||
|
||||
class Extensions_Database_Operation_RowBasedTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!extension_loaded('pdo_sqlite')) {
|
||||
$this->markTestSkipped('PDO/SQLite is required to run this test.');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
{
|
||||
return new DefaultConnection(DBUnitTestUtility::getSQLiteMemoryDB(), 'sqlite');
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
$tables = [
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table1',
|
||||
['table1_id', 'column1', 'column2', 'column3', 'column4'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table2',
|
||||
['table2_id', 'column5', 'column6', 'column7', 'column8'])
|
||||
),
|
||||
new DefaultTable(
|
||||
new DefaultTableMetadata('table3',
|
||||
['table3_id', 'column9', 'column10', 'column11', 'column12'])
|
||||
),
|
||||
];
|
||||
|
||||
return new DefaultDataSet($tables);
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$connection = $this->getConnection();
|
||||
/* @var $connection DefaultConnection */
|
||||
$table1 = new DefaultTable(
|
||||
new DefaultTableMetadata('table1', ['table1_id', 'column1', 'column2', 'column3', 'column4'])
|
||||
);
|
||||
|
||||
$table1->addRow([
|
||||
'table1_id' => 1,
|
||||
'column1' => 'foo',
|
||||
'column2' => 42,
|
||||
'column3' => 4.2,
|
||||
'column4' => 'bar'
|
||||
]);
|
||||
|
||||
$table1->addRow([
|
||||
'table1_id' => 2,
|
||||
'column1' => 'qwerty',
|
||||
'column2' => 23,
|
||||
'column3' => 2.3,
|
||||
'column4' => 'dvorak'
|
||||
]);
|
||||
|
||||
$table2 = new DefaultTable(
|
||||
new DefaultTableMetadata('table2', ['table2_id', 'column5', 'column6', 'column7', 'column8'])
|
||||
);
|
||||
|
||||
$table2->addRow([
|
||||
'table2_id' => 1,
|
||||
'column5' => 'fdyhkn',
|
||||
'column6' => 64,
|
||||
'column7' => 4568.64,
|
||||
'column8' => 'hkladfg'
|
||||
]);
|
||||
|
||||
$dataSet = new DefaultDataSet([$table1, $table2]);
|
||||
|
||||
$mockOperation = $this->createPartialMock(
|
||||
RowBased::class,
|
||||
['buildOperationQuery', 'buildOperationArguments']
|
||||
);
|
||||
|
||||
/* @var $mockOperation PHPUnit_Framework_MockObject_MockObject */
|
||||
$mockOperation->expects($this->at(0))
|
||||
->method('buildOperationQuery')
|
||||
->with($connection->createDataSet()->getTableMetaData('table1'), $table1)
|
||||
->will(
|
||||
$this->returnValue('INSERT INTO table1 (table1_id, column1, column2, column3, column4) VALUES (?, ?, ?, ?, ?)')
|
||||
);
|
||||
|
||||
$mockOperation->expects($this->at(1))
|
||||
->method('buildOperationArguments')
|
||||
->with($connection->createDataSet()->getTableMetaData('table1'), $table1, 0)
|
||||
->will(
|
||||
$this->returnValue([1, 'foo', 42, 4.2, 'bar'])
|
||||
);
|
||||
|
||||
$mockOperation->expects($this->at(2))
|
||||
->method('buildOperationArguments')
|
||||
->with($connection->createDataSet()->getTableMetaData('table1'), $table1, 1)
|
||||
->will(
|
||||
$this->returnValue([2, 'qwerty', 23, 2.3, 'dvorak'])
|
||||
);
|
||||
|
||||
$mockOperation->expects($this->at(3))
|
||||
->method('buildOperationQuery')
|
||||
->with($connection->createDataSet()->getTableMetaData('table2'), $table2)
|
||||
->will(
|
||||
$this->returnValue('INSERT INTO table2 (table2_id, column5, column6, column7, column8) VALUES (?, ?, ?, ?, ?)')
|
||||
);
|
||||
|
||||
$mockOperation->expects($this->at(4))
|
||||
->method('buildOperationArguments')
|
||||
->with($connection->createDataSet()->getTableMetaData('table2'), $table2, 0)
|
||||
->will(
|
||||
$this->returnValue([1, 'fdyhkn', 64, 4568.64, 'hkladfg'])
|
||||
);
|
||||
|
||||
/* @var $mockOperation RowBased */
|
||||
$mockOperation->execute($connection, $dataSet);
|
||||
|
||||
$this->assertDataSetsEqual(new FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/RowBasedExecute.xml'), $connection->createDataSet(['table1', 'table2']));
|
||||
}
|
||||
|
||||
public function testExecuteWithBadQuery()
|
||||
{
|
||||
$mockDatabaseDataSet = $this->createMock(DefaultDataSet::class);
|
||||
$mockDatabaseDataSet->expects($this->never())->method('getTableMetaData');
|
||||
|
||||
$mockConnection = $this->createMock(Connection::class);
|
||||
$mockConnection->expects($this->once())->method('createDataSet')->will($this->returnValue($mockDatabaseDataSet));
|
||||
foreach (['getConnection', 'disablePrimaryKeys', 'enablePrimaryKeys'] as $method) {
|
||||
$mockConnection->expects($this->never())->method($method);
|
||||
}
|
||||
|
||||
$mockTableMetaData = $this->createMock(ITableMetadata::class);
|
||||
$mockTableMetaData->expects($this->any())->method('getTableName')->will($this->returnValue('table'));
|
||||
$mockTable = $this->createMock(ITable::class);
|
||||
$mockTable->expects($this->any())->method('getTableMetaData')->will($this->returnValue($mockTableMetaData));
|
||||
$mockTable->expects($this->once())->method('getRowCount')->will($this->returnValue(0));
|
||||
|
||||
$mockDataSet = $this->createMock(DefaultDataSet::class);
|
||||
$mockDataSet->expects($this->once())->method('getIterator')->will($this->returnValue(new ArrayIterator([$mockTable])));
|
||||
|
||||
$mockOperation = $this->createPartialMock(
|
||||
RowBased::class,
|
||||
['buildOperationQuery', 'buildOperationArguments']
|
||||
);
|
||||
$mockOperation->expects($this->never())->method('buildOperationArguments');
|
||||
$mockOperation->expects($this->never())->method('buildOperationQuery');
|
||||
|
||||
$mockOperation->execute($mockConnection, $mockDataSet);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user