├── .gitattributes
├── .gitignore
├── Tests
├── _files
│ ├── XmlDataSets
│ │ ├── AllEmptyTableInsertTest.xml
│ │ ├── DeleteOperationTest.xml
│ │ ├── DeleteAllOperationTest.xml
│ │ ├── FlatXmlWriterEntities.xml
│ │ ├── XmlWriterEntities.xml
│ │ ├── RowBasedExecute.xml
│ │ ├── EmptyTableInsertTest.xml
│ │ ├── InsertOperationTest.xml
│ │ ├── UpdateOperationTest.xml
│ │ ├── DeleteOperationResult.xml
│ │ ├── FilteredTestFixture.xml
│ │ ├── FlatXmlDataSet.xml
│ │ ├── QueryDataSetTest.xml
│ │ ├── FlatXmlWriter.xml
│ │ ├── FilteredTestComparison.xml
│ │ ├── OperationsTestFixture.xml
│ │ ├── AllEmptyTableInsertResult.xml
│ │ ├── ReplaceOperationTest.xml
│ │ ├── OperationsMySQLTestFixture.xml
│ │ ├── UpdateOperationResult.xml
│ │ ├── XmlWriter.xml
│ │ ├── EmptyTableInsertResult.xml
│ │ ├── InsertOperationResult.xml
│ │ ├── ReplaceOperationResult.xml
│ │ ├── MysqlXmlDataSet.xml
│ │ └── XmlDataSet.xml
│ ├── CsvDataSets
│ │ ├── table1.csv
│ │ └── table2.csv
│ └── YamlDataSets
│ │ └── testDataSet.yaml
├── DB
│ └── DefaultDatabaseConnectionTest.php
├── Constraint
│ └── TableRowCountTest.php
└── DataSet
│ └── AbstractTableTest.php
├── Samples
└── BankAccountDB
│ └── _files
│ ├── bank-account-seed.xml
│ ├── bank-account-after-deposits.xml
│ ├── bank-account-after-withdrawals.xml
│ └── bank-account-after-new-account.xml
├── ChangeLog.markdown
├── phpunit.xml.dist
├── LICENSE
├── dbunit.bat
├── dbunit.php
└── PHPUnit
└── Extensions
└── Database
├── Exception.php
├── IDatabaseListConsumer.php
├── DataSet
├── Specs
│ ├── IFactory.php
│ ├── Xml.php
│ ├── Yaml.php
│ ├── FlatXml.php
│ ├── Factory.php
│ ├── DbTable.php
│ └── DbQuery.php
├── ISpec.php
├── IPersistable.php
├── ITableIterator.php
├── ITableMetaData.php
├── DefaultTableMetaData.php
├── ITable.php
├── DefaultDataSet.php
├── Persistors
│ ├── Factory.php
│ └── Yaml.php
├── IDataSet.php
├── FlatXmlDataSet.php
├── AbstractTableMetaData.php
└── DefaultTable.php
├── Autoload.php.in
├── Operation
├── Null.php
├── IDatabaseOperation.php
├── DeleteAll.php
├── Truncate.php
├── Delete.php
├── Composite.php
├── Update.php
├── Exception.php
└── Insert.php
├── UI
├── IMode.php
├── IMediumPrinter.php
├── IModeFactory.php
├── IMedium.php
├── Context.php
├── InvalidModeException.php
└── Command.php
├── DB
├── TableMetaData.php
├── FilteredDataSet.php
├── Table.php
├── ResultSetTable.php
├── IMetaData.php
└── MetaData
│ └── MySQL.php
├── DefaultTester.php
├── Constraint
├── TableRowCount.php
├── TableIsEqual.php
└── DataSetIsEqual.php
└── ITester.php
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.php diff=php
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build/api
2 | build/code-browser
3 | build/coverage
4 | build/logs
5 | build/pdepend
6 | cache.properties
7 | phpunit.xml
8 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/AllEmptyTableInsertTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/DeleteOperationTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Tests/_files/CsvDataSets/table1.csv:
--------------------------------------------------------------------------------
1 | table1_id,column1,column2,column3,column4
2 | 1,tgfahgasdf,200,34.64,"yghkf;a hahfg8ja h;"
3 | 2,hk;afg,654,46.54,24rwehhads
4 | 3,ha;gyt,462,1654.4,asfgklg
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/DeleteAllOperationTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/FlatXmlWriterEntities.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/Tests/_files/CsvDataSets/table2.csv:
--------------------------------------------------------------------------------
1 | table2_id,column5,column6,column7,column8
2 | 1,fhah,456,46.5,"fsdb, ghfdas"
3 | 2,asdhfoih,654,blah,"43asd ""fhgj"" sfadh"
4 | 3,ajsdlkfguitah,654,blah,"thesethasdl
5 | asdflkjsadf asdfsadfhl ""adsf, halsdf"" sadfhlasdf"
--------------------------------------------------------------------------------
/Samples/BankAccountDB/_files/bank-account-seed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/BankAccountDB/_files/bank-account-after-deposits.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/BankAccountDB/_files/bank-account-after-withdrawals.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/XmlWriterEntities.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | col1
5 | col2
6 |
7 | 1
8 | <?xml version="1.0"?><myxml>test</myxml>
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/RowBasedExecute.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/EmptyTableInsertTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Samples/BankAccountDB/_files/bank-account-after-new-account.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/InsertOperationTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/UpdateOperationTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/DeleteOperationResult.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/FilteredTestFixture.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ChangeLog.markdown:
--------------------------------------------------------------------------------
1 | DbUnit 1.1
2 | ==========
3 |
4 | This is the list of changes for the DbUnit 1.1 release series.
5 |
6 | DbUnit 1.1.2
7 | -------------
8 |
9 | * `PHPUnit_Extensions_Database_Constraint_TableIsEqual` did not work with PHPUnit 3.6 and DbUnit 1.1.
10 |
11 | DbUnit 1.1.1
12 | -------------
13 |
14 | * `PHPUnit_Extensions_Database_TestCase` test cases did not work at all with PHPUnit 3.6 and DbUnit 1.1.
15 |
16 | DbUnit 1.1.0
17 | -------------
18 |
19 | * Added support for MS SQL Server.
20 | * Added `assertTableRowCount()`.
21 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/FlatXmlDataSet.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/QueryDataSetTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
17 |
24 |
31 |
32 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/FlatXmlWriter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
13 |
18 |
19 |
24 |
28 |
32 |
33 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/FilteredTestComparison.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/OperationsTestFixture.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/AllEmptyTableInsertResult.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/ReplaceOperationTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/OperationsMySQLTestFixture.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/UpdateOperationResult.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/XmlWriter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | col1
5 | col2
6 | col3
7 |
8 | val1
9 | val2
10 | val3
11 |
12 |
13 |
14 |
15 | val4
16 |
17 |
18 | val5
19 | val6
20 | val7
21 |
22 |
23 |
24 | col1
25 | col2
26 | col3
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/EmptyTableInsertResult.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Tests/_files/YamlDataSets/testDataSet.yaml:
--------------------------------------------------------------------------------
1 | table1:
2 | -
3 | table1_id: 1
4 | column1: "tgfahgasdf"
5 | column2: 200
6 | column3: 34.64
7 | column4: "yghkf;a hahfg8ja h;"
8 | -
9 | table1_id: 2
10 | column1: "hk;afg"
11 | column2: 654
12 | column3: 46.54
13 | column4: 24rwehhads
14 | extraColumn: 'causes no worries'
15 | -
16 | table1_id: 3
17 | column1: ha;gyt
18 | column2: 462
19 | column3: 1654.4
20 | column4: asfgklg
21 | table2:
22 | -
23 | table2_id: 1
24 | column5: fhah
25 | column6: 456
26 | column7: 46.5
27 | column8: "fsdb, ghfdas"
28 | -
29 | table2_id: 2
30 | column5: asdhfoih
31 | column6: 654
32 | column7: blah
33 | column8: "43asd \"fhgj\" sfadh"
34 | -
35 | table2_id: 3
36 | column5: ajsdlkfguitah
37 | column6: 654
38 | column7: blah
39 | column8: |-
40 | thesethasdl
41 | asdflkjsadf asdfsadfhl "adsf, halsdf" sadfhlasdf
42 |
43 | emptyTable:
44 |
45 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/InsertOperationResult.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Tests/DB/DefaultDatabaseConnectionTest.php:
--------------------------------------------------------------------------------
1 | db = new PDO('sqlite::memory:');
9 | $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
10 | $this->db->exec('CREATE TABLE test (field1 VARCHAR(100))');
11 | }
12 |
13 | public function testRowCountForEmptyTableReturnsZero()
14 | {
15 | $conn = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($this->db);
16 | $this->assertEquals(0, $conn->getRowCount('test'));
17 | }
18 |
19 | public function testRowCountForTableWithTwoRowsReturnsTwo()
20 | {
21 | $this->db->exec('INSERT INTO test (field1) VALUES (\'foobar\')');
22 | $this->db->exec('INSERT INTO test (field1) VALUES (\'foobarbaz\')');
23 |
24 | $conn = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($this->db);
25 | $this->assertEquals(2, $conn->getRowCount('test'));
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/ReplaceOperationResult.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Tests/DataSet
12 | Tests/Operation
13 | Tests/DB
14 |
15 |
16 |
17 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | PHPUnit
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | DbUnit
2 |
3 | Copyright (c) 2002-2012, Sebastian Bergmann .
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions
8 | are met:
9 |
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 |
13 | * Redistributions in binary form must reproduce the above copyright
14 | notice, this list of conditions and the following disclaimer in
15 | the documentation and/or other materials provided with the
16 | distribution.
17 |
18 | * Neither the name of Sebastian Bergmann nor the names of his
19 | contributors may be used to endorse or promote products derived
20 | from this software without specific prior written permission.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | POSSIBILITY OF SUCH DAMAGE.
34 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/MysqlXmlDataSet.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 1
7 | tgfahgasdf
8 | 200
9 | 34.64
10 | yghkf;a hahfg8ja h;
11 |
12 |
13 | 2
14 | hk;afg
15 | 654
16 | 46.54
17 | 24rwehhads
18 |
19 |
20 | 3
21 | ha;gyt
22 | 462
23 | 1654.4
24 | asfgklg
25 |
26 |
27 |
28 |
29 | 1
30 | fhah
31 | 456
32 | 46.5
33 | fsdbghfdas
34 |
35 |
36 | 2
37 | asdhfoih
38 | 654
39 |
40 | 43asdfhgj
41 |
42 |
43 | 3
44 | ajsdlkfguitah
45 | 654
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/Tests/_files/XmlDataSets/XmlDataSet.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | table1_id
5 | column1
6 | column2
7 | column3
8 | column4
9 |
10 | 1
11 | tgfahgasdf
12 | 200
13 | 34.64
14 | yghkf;a hahfg8ja h;
15 |
16 |
17 | 2
18 | hk;afg
19 | 654
20 | 46.54
21 | 24rwehhads
22 |
23 |
24 | 3
25 | ha;gyt
26 | 462
27 | 1654.4
28 | asfgklg
29 |
30 |
31 |
32 | table2_id
33 | column5
34 | column6
35 | column7
36 | column8
37 |
38 | 1
39 | fhah
40 | 456
41 | 46.5
42 | fsdbghfdas
43 |
44 |
45 | 2
46 | asdhfoih
47 | 654
48 |
49 | 43asdfhgj
50 |
51 |
52 | 3
53 | ajsdlkfguitah
54 | 654
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/dbunit.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | REM PHPUnit
3 | REM
4 | REM Copyright (c) 2002-2010, Sebastian Bergmann .
5 | REM All rights reserved.
6 | REM
7 | REM Redistribution and use in source and binary forms, with or without
8 | REM modification, are permitted provided that the following conditions
9 | REM are met:
10 | REM
11 | REM * Redistributions of source code must retain the above copyright
12 | REM notice, this list of conditions and the following disclaimer.
13 | REM
14 | REM * Redistributions in binary form must reproduce the above copyright
15 | REM notice, this list of conditions and the following disclaimer in
16 | REM the documentation and/or other materials provided with the
17 | REM distribution.
18 | REM
19 | REM * Neither the name of Sebastian Bergmann nor the names of his
20 | REM contributors may be used to endorse or promote products derived
21 | REM from this software without specific prior written permission.
22 | REM
23 | REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | REM "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | REM LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | REM FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 | REM COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 | REM INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | REM BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | REM LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | REM CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
32 | REM LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 | REM ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | REM POSSIBILITY OF SUCH DAMAGE.
35 | REM
36 |
37 | if "%PHPBIN%" == "" set PHPBIN=@php_bin@
38 | if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
39 | GOTO RUN
40 | :USE_PEAR_PATH
41 | set PHPBIN=%PHP_PEAR_PHP_BIN%
42 | :RUN
43 | "%PHPBIN%" "@bin_dir@\dbunit" %*
44 |
--------------------------------------------------------------------------------
/dbunit.php:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | */
37 |
38 | if (strpos('@php_bin@', '@php_bin') === 0) {
39 | set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
40 | }
41 |
42 | require_once 'PHPUnit/Autoload.php';
43 |
44 | PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'PHPUNIT');
45 |
46 | $command = new PHPUnit_Extensions_Database_UI_Command(
47 | new PHPUnit_Extensions_Database_UI_ModeFactory()
48 | );
49 |
50 | $command->main(
51 | new PHPUnit_Extensions_Database_UI_Mediums_Text($_SERVER['argv']),
52 | new PHPUnit_Extensions_Database_UI_Context()
53 | );
54 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Exception.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Thrown for exceptions encountered with database operations. Provides
47 | * information regarding which operations failed and the query (if any) it
48 | * failed on.
49 | *
50 | * @package DbUnit
51 | * @author Mike Lively
52 | * @copyright 2010 Mike Lively
53 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
54 | * @version Release: @package_version@
55 | * @link http://www.phpunit.de/
56 | * @since Class available since Release 1.0.0
57 | */
58 | class PHPUnit_Extensions_Database_Exception extends Exception
59 | {
60 | }
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/IDatabaseListConsumer.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * An interface for classes that require a list of databases to operate.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_IDatabaseListConsumer
57 | {
58 | /**
59 | * Sets the database for the spec
60 | *
61 | * @param array $databases
62 | */
63 | public function setDatabases(array $databases);
64 | }
65 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Specs/IFactory.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * An interface for data set spec factories.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_DataSet_Specs_IFactory
57 | {
58 | /**
59 | * Returns the data set
60 | *
61 | * @param string $type
62 | * @return PHPUnit_Extensions_Database_DataSet_ISpec
63 | */
64 | public function getDataSetSpecByType($type);
65 | }
66 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Autoload.php.in:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2010 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.1.0
43 | */
44 |
45 | function phpunit_dbunit_autoload($class = NULL) {
46 | static $classes = NULL;
47 | static $path = NULL;
48 |
49 | if ($classes === NULL) {
50 | $classes = array(
51 | ___CLASSLIST___
52 | );
53 |
54 | $path = dirname(dirname(dirname(__FILE__)));
55 | }
56 |
57 | if ($class === NULL) {
58 | $result = array(__FILE__);
59 |
60 | foreach ($classes as $file) {
61 | $result[] = $path . $file;
62 | }
63 |
64 | return $result;
65 | }
66 |
67 | $cn = strtolower($class);
68 |
69 | if (isset($classes[$cn])) {
70 | $file = $path . $classes[$cn];
71 |
72 | require $file;
73 | }
74 | }
75 |
76 | spl_autoload_register('phpunit_dbunit_autoload');
77 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/ISpec.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides an interface for creating data sets from data set spec strings.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_DataSet_ISpec
57 | {
58 | /**
59 | * Creates a data set from a data set spec string.
60 | *
61 | * @param string $dataSetSpec
62 | * @return PHPUnit_Extensions_Database_DataSet_IDataSet
63 | */
64 | public function getDataSet($dataSetSpec);
65 | }
66 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/Null.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * This class represents a null database operation.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2002-2012 Sebastian Bergmann
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Operation_Null implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
57 | {
58 |
59 | public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
60 | {
61 | /* do nothing */
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/IPersistable.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * An interface for persisting datasets
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_DataSet_IPersistable
57 | {
58 | /**
59 | * Writes the given dataset
60 | *
61 | * The previous dataset will be overwritten.
62 | *
63 | * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataset
64 | */
65 | public function write(PHPUnit_Extensions_Database_DataSet_IDataSet $dataset);
66 | }
67 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/UI/IMode.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Defines the interface necessary to create new modes
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_UI_IMode
57 | {
58 | /**
59 | * Executes the mode using the given arguments and medium.
60 | *
61 | * @param array $modeArguments
62 | * @param PHPUnit_Extensions_Database_UI_IMediumPrinter $medium
63 | */
64 | public function execute(array $modeArguments, PHPUnit_Extensions_Database_UI_IMediumPrinter $medium);
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/UI/IMediumPrinter.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Defines the interface necessary to create new medium printers.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_UI_IMediumPrinter
57 | {
58 | /**
59 | * Prints standard output messages.
60 | *
61 | * @param string $message
62 | */
63 | public function output($message);
64 |
65 | /**
66 | * Prints standard error messages.
67 | *
68 | * @param string $message
69 | */
70 | public function error($message);
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/UI/IModeFactory.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Defines the interface necessary to create new mode factories
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_UI_IModeFactory
57 | {
58 | /**
59 | * Generates a new mode based on a given name.
60 | *
61 | * @param string $mode
62 | * @return PHPUnit_Extensions_Database_UI_IMode
63 | */
64 | public function getMode($mode);
65 |
66 | /**
67 | * Returns the names of valid modes this factory can create.
68 | *
69 | * @return array
70 | */
71 | public function getModeList();
72 | }
73 |
74 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DB/TableMetaData.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * This class loads a table metadata object with database metadata.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DB_TableMetaData extends PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData
57 | {
58 |
59 | public function __construct($tableName, PHPUnit_Extensions_Database_DB_IMetaData $databaseMetaData)
60 | {
61 | $this->tableName = $tableName;
62 | $this->columns = $databaseMetaData->getTableColumns($tableName);
63 | $this->primaryKeys = $databaseMetaData->getTablePrimaryKeys($tableName);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/ITableIterator.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides a basic interface for creating and reading data from data sets.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_DataSet_ITableIterator extends Iterator
57 | {
58 |
59 | /**
60 | * Returns the current table.
61 | *
62 | * @return PHPUnit_Extensions_Database_DataSet_ITable
63 | */
64 | public function getTable();
65 |
66 | /**
67 | * Returns the current table's meta data.
68 | *
69 | * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData
70 | */
71 | public function getTableMetaData();
72 | }
73 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/UI/IMedium.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Defines the interface necessary to create new mediums.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_UI_IMedium extends PHPUnit_Extensions_Database_UI_IMediumPrinter
57 | {
58 | /**
59 | * Builds the context for the application.
60 | *
61 | * @param PHPUnit_Extensions_Database_UI_Context $context
62 | */
63 | public function buildContext(PHPUnit_Extensions_Database_UI_Context $context);
64 |
65 | /**
66 | * Handles the displaying of exceptions received from the application.
67 | *
68 | * @param Exception $e
69 | */
70 | public function handleException(Exception $e);
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/Tests/Constraint/TableRowCountTest.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * @package DbUnit
47 | * @author Mike Lively
48 | * @copyright 2002-2012 Sebastian Bergmann
49 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
50 | * @link http://www.phpunit.de/
51 | * @since File available since Release 1.0.0
52 | */
53 | class Extensions_Database_Constraint_TableRowCountTest extends PHPUnit_Framework_TestCase
54 | {
55 | public function testConstraint()
56 | {
57 | $constraint = new PHPUnit_Extensions_Database_Constraint_TableRowCount('name', 42);
58 | $this->assertTrue($constraint->evaluate(42));
59 | $this->assertFalse($constraint->evaluate(24));
60 | $this->assertEquals('is equal to expected row count 42', $constraint->toString());
61 |
62 | try {
63 | $constraint->fail(24, '');
64 | }
65 |
66 | catch (PHPUnit_Framework_ExpectationFailedException $e) {
67 | $this->assertEquals('Failed asserting that table "name" has 42 rows (actual row count: 24)', $e->getMessage());
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Specs/Xml.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0CSV
43 | */
44 |
45 | /**
46 | * Creates a XML dataset based off of a spec string.
47 | *
48 | * The format of the spec string is as follows:
49 | *
50 | *
51 | *
52 | * The filename should be the location of a xml file relative to the
53 | * current working directory.
54 | *
55 | * @package DbUnit
56 | * @author Mike Lively
57 | * @copyright 2010 Mike Lively
58 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
59 | * @version Release: @package_version@
60 | * @link http://www.phpunit.de//**
61 | * @since Class available since Release 1.0.0
62 | */
63 | class PHPUnit_Extensions_Database_DataSet_Specs_Xml implements PHPUnit_Extensions_Database_DataSet_ISpec
64 | {
65 | /**
66 | * Creates XML Data Set from a data set spec.
67 | *
68 | * @param string $dataSetSpec
69 | * @return PHPUnit_Extensions_Database_DataSet_XmlDataSet
70 | */
71 | public function getDataSet($dataSetSpec)
72 | {
73 | return new PHPUnit_Extensions_Database_DataSet_XmlDataSet($dataSetSpec);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Specs/Yaml.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0CSV
43 | */
44 |
45 | /**
46 | * Creates a YAML dataset based off of a spec string.
47 | *
48 | * The format of the spec string is as follows:
49 | *
50 | *
51 | *
52 | * The filename should be the location of a yaml file relative to the
53 | * current working directory.
54 | *
55 | * @package DbUnit
56 | * @author Mike Lively
57 | * @copyright 2010 Mike Lively
58 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
59 | * @version Release: @package_version@
60 | * @link http://www.phpunit.de//**
61 | * @since Class available since Release 1.0.0
62 | */
63 | class PHPUnit_Extensions_Database_DataSet_Specs_Yaml implements PHPUnit_Extensions_Database_DataSet_ISpec
64 | {
65 | /**
66 | * Creates YAML Data Set from a data set spec.
67 | *
68 | * @param string $dataSetSpec
69 | * @return PHPUnit_Extensions_Database_DataSet_YamlDataSet
70 | */
71 | public function getDataSet($dataSetSpec)
72 | {
73 | return new PHPUnit_Extensions_Database_DataSet_YamlDataSet($dataSetSpec);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides a basic interface and functionality for executing database
47 | * operations against a connection using a specific dataSet.
48 | *
49 | * @package DbUnit
50 | * @author Mike Lively
51 | * @copyright 2010 Mike Lively
52 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
53 | * @version Release: @package_version@
54 | * @link http://www.phpunit.de/
55 | * @since Class available since Release 1.0.0
56 | */
57 | interface PHPUnit_Extensions_Database_Operation_IDatabaseOperation
58 | {
59 |
60 | /**
61 | * Executes the database operation against the given $connection for the
62 | * given $dataSet.
63 | *
64 | * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
65 | * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
66 | * @throws PHPUnit_Extensions_Database_Operation_Exception
67 | */
68 | public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet);
69 | }
70 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Specs/FlatXml.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0CSV
43 | */
44 |
45 | /**
46 | * Creates a FlatXML dataset based off of a spec string.
47 | *
48 | * The format of the spec string is as follows:
49 | *
50 | *
51 | *
52 | * The filename should be the location of a flat xml file relative to the
53 | * current working directory.
54 | *
55 | * @package DbUnit
56 | * @author Mike Lively
57 | * @copyright 2010 Mike Lively
58 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
59 | * @version Release: @package_version@
60 | * @link http://www.phpunit.de//**
61 | * @since Class available since Release 1.0.0
62 | */
63 | class PHPUnit_Extensions_Database_DataSet_Specs_FlatXml implements PHPUnit_Extensions_Database_DataSet_ISpec
64 | {
65 | /**
66 | * Creates Flat XML Data Set from a data set spec.
67 | *
68 | * @param string $dataSetSpec
69 | * @return PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet
70 | */
71 | public function getDataSet($dataSetSpec)
72 | {
73 | return new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet($dataSetSpec);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/ITableMetaData.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides a basic interface for returning table meta data.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_DataSet_ITableMetaData
57 | {
58 |
59 | /**
60 | * Returns the names of the columns in the table.
61 | *
62 | * @return array
63 | */
64 | public function getColumns();
65 |
66 | /**
67 | * Returns the names of the primary key columns in the table.
68 | *
69 | * @return array
70 | */
71 | public function getPrimaryKeys();
72 |
73 | /**
74 | * Returns the name of the table.
75 | *
76 | * @return string
77 | */
78 | public function getTableName();
79 |
80 | /**
81 | * Asserts that the given tableMetaData matches this tableMetaData.
82 | *
83 | * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $other
84 | */
85 | public function matches(PHPUnit_Extensions_Database_DataSet_ITableMetaData $other);
86 | }
87 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DB/FilteredDataSet.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides access to a database instance as a data set.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DB_FilteredDataSet extends PHPUnit_Extensions_Database_DB_DataSet
57 | {
58 |
59 | /**
60 | * @var Array
61 | */
62 | protected $tableNames;
63 |
64 | /**
65 | * Creates a new dataset using the given database connection.
66 | *
67 | * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection
68 | */
69 | public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection, Array $tableNames)
70 | {
71 | parent::__construct($databaseConnection);
72 | $this->tableNames = $tableNames;
73 | }
74 |
75 | /**
76 | * Returns a list of table names for the database
77 | *
78 | * @return Array
79 | */
80 | public function getTableNames()
81 | {
82 | return $this->tableNames;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DB/Table.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides the functionality to represent a database table.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DB_Table extends PHPUnit_Extensions_Database_DataSet_AbstractTable
57 | {
58 |
59 | /**
60 | * Creates a new database table object.
61 | *
62 | * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData
63 | * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection
64 | */
65 | public function __construct(PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData, PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection)
66 | {
67 | $this->setTableMetaData($tableMetaData);
68 |
69 | $pdoStatement = $databaseConnection->getConnection()->prepare(PHPUnit_Extensions_Database_DB_DataSet::buildTableSelect($tableMetaData, $databaseConnection));
70 | $pdoStatement->execute();
71 | $this->data = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/DeleteAll.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Deletes all rows from all tables in a dataset.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Operation_DeleteAll implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
57 | {
58 |
59 | public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
60 | {
61 | foreach ($dataSet->getReverseIterator() as $table) {
62 | /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */
63 |
64 | $query = "
65 | DELETE FROM {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())}
66 | ";
67 |
68 | try {
69 | $connection->getConnection()->query($query);
70 | } catch (PDOException $e) {
71 | throw new PHPUnit_Extensions_Database_Operation_Exception('DELETE_ALL', $query, array(), $table, $e->getMessage());
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * The default implementation of table meta data
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData extends PHPUnit_Extensions_Database_DataSet_AbstractTableMetaData
57 | {
58 |
59 | /**
60 | * Creates a new default table meta data object.
61 | *
62 | * @param string $tableName
63 | * @param array $columns
64 | * @param array $primaryKeys
65 | */
66 | public function __construct($tableName, Array $columns, Array $primaryKeys = array())
67 | {
68 | $this->tableName = $tableName;
69 | $this->columns = $columns;
70 | $this->primaryKeys = array();
71 |
72 | foreach ($primaryKeys as $columnName) {
73 | if (!in_array($columnName, $this->columns)) {
74 | throw new InvalidArgumentException("Primary key column passed that is not in the column list.");
75 | } else {
76 | $this->primaryKeys[] = $columnName;
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DefaultTester.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * This is the default implementation of the database tester. It receives its
47 | * connection object from the constructor.
48 | *
49 | * @package DbUnit
50 | * @author Mike Lively
51 | * @copyright 2010 Mike Lively
52 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
53 | * @version Release: @package_version@
54 | * @link http://www.phpunit.de/
55 | * @since Class available since Release 1.0.0
56 | */
57 | class PHPUnit_Extensions_Database_DefaultTester extends PHPUnit_Extensions_Database_AbstractTester
58 | {
59 |
60 | /**
61 | * @var PHPUnit_Extensions_Database_DB_IDatabaseConnection
62 | */
63 | protected $connection;
64 |
65 | /**
66 | * Creates a new default database tester using the given connection.
67 | *
68 | * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
69 | */
70 | public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection)
71 | {
72 | parent::__construct();
73 |
74 | $this->connection = $connection;
75 | }
76 |
77 | /**
78 | * Returns the test database connection.
79 | *
80 | * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
81 | */
82 | public function getConnection()
83 | {
84 | return $this->connection;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/UI/Context.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Holds the context of a particular database extension ui call.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_UI_Context
57 | {
58 | /**
59 | * @var string
60 | */
61 | protected $mode;
62 |
63 | /**
64 | * @var array
65 | */
66 | protected $modeArguments;
67 |
68 | /**
69 | * @param string $mode
70 | */
71 | public function setMode($mode)
72 | {
73 | $this->mode = $mode;
74 | }
75 |
76 | /**
77 | * @return string
78 | */
79 | public function getMode()
80 | {
81 | return $this->mode;
82 | }
83 |
84 | /**
85 | * @param array $arguments
86 | */
87 | public function setModeArguments(array $arguments)
88 | {
89 | $this->mode_arguments = $arguments;
90 | }
91 |
92 | /**
93 | * @return array
94 | */
95 | public function getModeArguments()
96 | {
97 | return $this->mode_arguments;
98 | }
99 | }
100 |
101 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DB/ResultSetTable.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides the functionality to represent a database result set as a DBUnit
47 | * table.
48 | *
49 | * @package DbUnit
50 | * @author Mike Lively
51 | * @copyright 2010 Mike Lively
52 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
53 | * @version Release: @package_version@
54 | * @link http://www.phpunit.de/
55 | * @deprecated The PHPUnit_Extension_Database_DataSet_QueryTable should be used instead
56 | * @see PHPUnit_Extension_Database_DataSet_QueryTable
57 | * @see PHPUnit_Extension_Database_DataSet_QueryDataSet
58 | * @since Class available since Release 1.0.0
59 | */
60 | class PHPUnit_Extensions_Database_DB_ResultSetTable extends PHPUnit_Extensions_Database_DataSet_AbstractTable
61 | {
62 |
63 | /**
64 | * Creates a new result set table.
65 | *
66 | * @param string $tableName
67 | * @param PDOStatement $pdoStatement
68 | */
69 | public function __construct($tableName, PDOStatement $pdoStatement)
70 | {
71 | $this->data = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
72 |
73 | if (count($this->data)) {
74 | $columns = array_keys($this->data[0]);
75 | } else {
76 | $columns = array();
77 | }
78 |
79 | $this->setTableMetaData(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns));
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/UI/InvalidModeException.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * An exception thrown when an invalid mode is requested from a mode factory.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_UI_InvalidModeException extends LogicException
57 | {
58 | /**
59 | * @var string
60 | */
61 | protected $mode;
62 |
63 | /**
64 | * @var PHPUnit_Extensions_Database_UI_IModeFactory
65 | */
66 | protected $modeFactory;
67 |
68 | /**
69 | * @param string $mode
70 | * @param string $msg
71 | * @param PHPUnit_Extensions_Database_UI_IModeFactory $modeFactory
72 | */
73 | public function __construct($mode, $msg, PHPUnit_Extensions_Database_UI_IModeFactory $modeFactory)
74 | {
75 | $this->mode = $mode;
76 | $this->modeFactory = $modeFactory;
77 | parent::__construct($msg);
78 | }
79 |
80 | /**
81 | * @return string
82 | */
83 | public function getMode()
84 | {
85 | return $this->mode;
86 | }
87 |
88 | /**
89 | * @return array
90 | */
91 | public function getValidModes()
92 | {
93 | return $this->modeFactory->getModeList();
94 | }
95 | }
96 |
97 |
--------------------------------------------------------------------------------
/Tests/DataSet/AbstractTableTest.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Sebastian Marek
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * @package DbUnit
47 | * @author Sebastian Marek
48 | * @copyright 2002-2012 Sebastian Bergmann
49 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
50 | * @link http://www.phpunit.de/
51 | * @since File available since Release 1.0.0
52 | */
53 | class Extensions_Database_DataSet_AbstractTableTest extends PHPUnit_Framework_TestCase
54 | {
55 | /**
56 | * @var PHPUnit_Extensions_Database_DataSet_QueryTable
57 | */
58 | protected $table;
59 |
60 | public function setUp()
61 | {
62 | $tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData(
63 | 'table', array('id', 'column1')
64 | );
65 |
66 | $this->table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($tableMetaData);
67 |
68 | $this->table->addRow(array(
69 | 'id' => 1,
70 | 'column1' => 'randomValue'
71 | ));
72 | }
73 |
74 | /**
75 | * @dataProvider providerTableContainsRow
76 | */
77 | public function testTableContainsRow($row, $exists)
78 | {
79 | $result = $this->table->assertContainsRow($row);
80 | $this->assertEquals($exists, $result);
81 | }
82 |
83 | public function providerTableContainsRow()
84 | {
85 | return array(
86 | array(array('id' => 1, 'column1' => 'randomValue'), true),
87 | array(array('id' => 1, 'column1' => 'notExistingValue'), false)
88 | );
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/ITable.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides a basic interface for creating and reading data from data sets.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_DataSet_ITable
57 | {
58 |
59 | /**
60 | * Returns the table's meta data.
61 | *
62 | * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData
63 | */
64 | public function getTableMetaData();
65 |
66 | /**
67 | * Returns the number of rows in this table.
68 | *
69 | * @return int
70 | */
71 | public function getRowCount();
72 |
73 | /**
74 | * Returns the value for the given column on the given row.
75 | *
76 | * @param int $row
77 | * @param int $column
78 | */
79 | public function getValue($row, $column);
80 |
81 | /**
82 | * Returns the an associative array keyed by columns for the given row.
83 | *
84 | * @param int $row
85 | * @return array
86 | */
87 | public function getRow($row);
88 |
89 | /**
90 | * Asserts that the given table matches this table.
91 | *
92 | * @param PHPUnit_Extensions_Database_DataSet_ITable $other
93 | */
94 | public function matches(PHPUnit_Extensions_Database_DataSet_ITable $other);
95 | }
96 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/UI/Command.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Delegates database extension commands to the appropriate mode classes.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_UI_Command
57 | {
58 | /**
59 | * @var PHPUnit_Extensions_Database_UI_IModeFactory
60 | */
61 | protected $modeFactory;
62 |
63 | /**
64 | * @param PHPUnit_Extensions_Database_UI_IModeFactory $modeFactory
65 | */
66 | public function __construct(PHPUnit_Extensions_Database_UI_IModeFactory $modeFactory)
67 | {
68 | $this->modeFactory = $modeFactory;
69 | }
70 |
71 | /**
72 | * Executes the database extension ui.
73 | *
74 | * @param PHPUnit_Extensions_Database_UI_IMedium $medium
75 | * @param PHPUnit_Extensions_Database_UI_Context $context
76 | */
77 | public function main(PHPUnit_Extensions_Database_UI_IMedium $medium, PHPUnit_Extensions_Database_UI_Context $context)
78 | {
79 | try {
80 | $medium->buildContext($context);
81 | $mode = $this->modeFactory->getMode($context->getMode());
82 | $mode->execute($context->getModeArguments(), $medium);
83 |
84 | } catch (Exception $e) {
85 | $medium->handleException($e);
86 | }
87 | }
88 | }
89 |
90 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/Truncate.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Executes a truncate against all tables in a dataset.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Operation_Truncate implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
57 | {
58 | protected $useCascade = FALSE;
59 |
60 | public function setCascade($cascade = TRUE)
61 | {
62 | $this->useCascade = $cascade;
63 | }
64 |
65 | public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
66 | {
67 | foreach ($dataSet->getReverseIterator() as $table) {
68 | /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */
69 | $query = "
70 | {$connection->getTruncateCommand()} {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())}
71 | ";
72 |
73 | if ($this->useCascade && $connection->allowsCascading()) {
74 | $query .= " CASCADE";
75 | }
76 |
77 | try {
78 | $connection->getConnection()->query($query);
79 | } catch (PDOException $e) {
80 | throw new PHPUnit_Extensions_Database_Operation_Exception('TRUNCATE', $query, array(), $table, $e->getMessage());
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * The default implementation of a data set.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DataSet_DefaultDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet
57 | {
58 |
59 | /**
60 | * An array of ITable objects.
61 | *
62 | * @var array
63 | */
64 | protected $tables;
65 |
66 | /**
67 | * Creates a new dataset using the given tables.
68 | *
69 | * @param array $tables
70 | */
71 | public function __construct(Array $tables = array())
72 | {
73 | $this->tables = $tables;
74 | }
75 |
76 | /**
77 | * Adds a table to the dataset.
78 | *
79 | * @param PHPUnit_Extensions_Database_DataSet_ITable $table
80 | */
81 | public function addTable(PHPUnit_Extensions_Database_DataSet_ITable $table)
82 | {
83 | $this->tables[] = $table;
84 | }
85 |
86 | /**
87 | * Creates an iterator over the tables in the data set. If $reverse is
88 | * true a reverse iterator will be returned.
89 | *
90 | * @param bool $reverse
91 | * @return PHPUnit_Extensions_Database_DataSet_ITableIterator
92 | */
93 | protected function createIterator($reverse = FALSE)
94 | {
95 | return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Specs/Factory.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Creates the appropriate DataSet Spec based on a given type.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DataSet_Specs_Factory implements PHPUnit_Extensions_Database_DataSet_Specs_IFactory
57 | {
58 | /**
59 | * Returns the data set
60 | *
61 | * @param string $type
62 | * @return PHPUnit_Extensions_Database_DataSet_ISpec
63 | */
64 | public function getDataSetSpecByType($type)
65 | {
66 | switch ($type) {
67 | case 'xml':
68 | return new PHPUnit_Extensions_Database_DataSet_Specs_Xml();
69 |
70 | case 'flatxml':
71 | return new PHPUnit_Extensions_Database_DataSet_Specs_FlatXml();
72 |
73 | case 'csv':
74 | return new PHPUnit_Extensions_Database_DataSet_Specs_Csv();
75 |
76 | case 'yaml':
77 | return new PHPUnit_Extensions_Database_DataSet_Specs_Yaml();
78 |
79 | case 'dbtable':
80 | return new PHPUnit_Extensions_Database_DataSet_Specs_DbTable();
81 |
82 | case 'dbquery':
83 | return new PHPUnit_Extensions_Database_DataSet_Specs_DbQuery();
84 |
85 | default:
86 | throw new PHPUnit_Extensions_Database_Exception("I don't know what you want from me.");
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Persistors/Factory.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Creates the appropriate Persistor based on a given type and spec.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de//**
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DataSet_Persistors_Factory
57 | {
58 | /**
59 | * Returns the persistor.
60 | *
61 | * @param string $type
62 | * @param string $spec
63 | * @return PHPUnit_Extensions_Database_DataSet_IPersistable
64 | */
65 | public function getPersistorBySpec($type, $spec)
66 | {
67 | switch (strtolower($type)) {
68 | case 'xml':
69 | $xmlPersistor = new PHPUnit_Extensions_Database_DataSet_Persistors_Xml();
70 | $xmlPersistor->setFileName($spec);
71 | return $xmlPersistor;
72 |
73 | case 'flatxml':
74 | $flatXmlPersistor = new PHPUnit_Extensions_Database_DataSet_Persistors_FlatXml();
75 | $flatXmlPersistor->setFileName($spec);
76 | return $flatXmlPersistor;
77 |
78 | case 'yaml':
79 | $yamlPersistor = new PHPUnit_Extensions_Database_DataSet_Persistors_Yaml();
80 | $yamlPersistor->setFileName($spec);
81 | return $yamlPersistor;
82 |
83 | default:
84 | throw new PHPUnit_Extensions_Database_Exception("I don't know what you want from me. PERSISTOR");
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/IDataSet.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides a basic interface for creating and reading data from data sets.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_DataSet_IDataSet extends IteratorAggregate
57 | {
58 |
59 | /**
60 | * Returns an array of table names contained in the dataset.
61 | *
62 | * @return array
63 | */
64 | public function getTableNames();
65 |
66 | /**
67 | * Returns a table meta data object for the given table.
68 | *
69 | * @param string $tableName
70 | * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData
71 | */
72 | public function getTableMetaData($tableName);
73 |
74 | /**
75 | * Returns a table object for the given table.
76 | *
77 | * @param string $tableName
78 | * @return PHPUnit_Extensions_Database_DataSet_ITable
79 | */
80 | public function getTable($tableName);
81 |
82 | /**
83 | * Returns a reverse iterator for all table objects in the given dataset.
84 | *
85 | * @return PHPUnit_Extensions_Database_DataSet_ITableIterator
86 | */
87 | public function getReverseIterator();
88 |
89 | /**
90 | * Asserts that the given data set matches this data set.
91 | *
92 | * @param PHPUnit_Extensions_Database_DataSet_IDataSet $other
93 | */
94 | public function matches(PHPUnit_Extensions_Database_DataSet_IDataSet $other);
95 | }
96 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/Delete.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Deletes the rows in a given dataset using primary key columns.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Operation_Delete extends PHPUnit_Extensions_Database_Operation_RowBased
57 | {
58 |
59 | protected $operationName = 'DELETE';
60 |
61 | protected $iteratorDirection = self::ITERATOR_TYPE_REVERSE;
62 |
63 | protected function buildOperationQuery(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection)
64 | {
65 | $keys = $databaseTableMetaData->getPrimaryKeys();
66 |
67 | $whereStatement = 'WHERE ' . implode(' AND ', $this->buildPreparedColumnArray($keys, $connection));
68 |
69 | $query = "
70 | DELETE FROM {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())}
71 | {$whereStatement}
72 | ";
73 |
74 | return $query;
75 | }
76 |
77 | protected function buildOperationArguments(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, $row)
78 | {
79 | $args = array();
80 | foreach ($databaseTableMetaData->getPrimaryKeys() as $columnName) {
81 | $args[] = $table->getValue($row, $columnName);
82 | }
83 |
84 | return $args;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Constraint/TableRowCount.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Asserts the row count in a table
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Constraint_TableRowCount extends PHPUnit_Framework_Constraint
57 | {
58 | /**
59 | * @var int
60 | */
61 | protected $value;
62 |
63 | /**
64 | * @var string
65 | */
66 | protected $tableName;
67 |
68 | /**
69 | * Creates a new constraint.
70 | *
71 | * @param int $expected
72 | */
73 | public function __construct($tableName, $value)
74 | {
75 | $this->tableName = $tableName;
76 | $this->value = $value;
77 | }
78 |
79 | /**
80 | * Evaluates the constraint for parameter $other. Returns TRUE if the
81 | * constraint is met, FALSE otherwise.
82 | *
83 | * This method can be overridden to implement the evaluation algorithm.
84 | *
85 | * @param mixed $other Value or object to evaluate.
86 | * @return bool
87 | */
88 | protected function matches($other)
89 | {
90 | return $other == $this->value;
91 | }
92 |
93 | /**
94 | * Returns a string representation of the constraint.
95 | *
96 | * @return string
97 | */
98 | public function toString()
99 | {
100 | return sprintf('is equal to expected row count %d', $this->value);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Persistors/Yaml.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * A yaml dataset persistor
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DataSet_Persistors_Yaml implements PHPUnit_Extensions_Database_DataSet_IPersistable
57 | {
58 | /**
59 | * @var string
60 | */
61 | protected $filename;
62 |
63 | /**
64 | * Sets the filename that this persistor will save to.
65 | *
66 | * @param string $filename
67 | */
68 | public function setFileName($filename)
69 | {
70 | $this->filename = $filename;
71 | }
72 |
73 | /**
74 | * Writes the dataset to a yaml file
75 | *
76 | * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataset
77 | */
78 | public function write(PHPUnit_Extensions_Database_DataSet_IDataSet $dataset)
79 | {
80 | $phpArr = array();
81 | $emptyTables = array();
82 |
83 | foreach ($dataset as $table) {
84 | $tableName = $table->getTableMetaData()->getTableName();
85 | $rowCount = $table->getRowCount();
86 |
87 | if (!$rowCount) {
88 | $emptyTables[] = $tableName;
89 | continue;
90 | }
91 |
92 | $phpArr[$tableName] = array();
93 |
94 | for ($i = 0; $i < $rowCount; $i++) {
95 | $phpArr[$tableName][] = $table->getRow($i);
96 | }
97 | }
98 |
99 | $emptyTablesAsString = '';
100 |
101 | if (count($emptyTables)) {
102 | $emptyTablesAsString = implode(":\n", $emptyTables) . ":\n\n";
103 | }
104 |
105 | file_put_contents(
106 | $this->filename, sfYaml::dump($phpArr, 3) . $emptyTablesAsString
107 | );
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/Composite.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * This class facilitates combining database operations. To create a composite
47 | * operation pass an array of classes that implement
48 | * PHPUnit_Extensions_Database_Operation_IDatabaseOperation and they will be
49 | * executed in that order against all data sets.
50 | *
51 | * @package DbUnit
52 | * @author Mike Lively
53 | * @copyright 2010 Mike Lively
54 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
55 | * @version Release: @package_version@
56 | * @link http://www.phpunit.de/
57 | * @since Class available since Release 1.0.0
58 | */
59 | class PHPUnit_Extensions_Database_Operation_Composite implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
60 | {
61 |
62 | /**
63 | * @var array
64 | */
65 | protected $operations = array();
66 |
67 | /**
68 | * Creates a composite operation.
69 | *
70 | * @param array $operations
71 | */
72 | public function __construct(Array $operations)
73 | {
74 | foreach ($operations as $operation) {
75 | if ($operation instanceof PHPUnit_Extensions_Database_Operation_IDatabaseOperation) {
76 | $this->operations[] = $operation;
77 | } else {
78 | throw new InvalidArgumentException("Only database operation instances can be passed to a composite database operation.");
79 | }
80 | }
81 | }
82 |
83 | public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
84 | {
85 | try {
86 | foreach ($this->operations as $operation) {
87 | /* @var $operation PHPUnit_Extensions_Database_Operation_IDatabaseOperation */
88 | $operation->execute($connection, $dataSet);
89 | }
90 | } catch (PHPUnit_Extensions_Database_Operation_Exception $e) {
91 | throw new PHPUnit_Extensions_Database_Operation_Exception("COMPOSITE[{$e->getOperation()}]", $e->getQuery(), $e->getArgs(), $e->getTable(), $e->getError());
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * The default implementation of a data set.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractXmlDataSet
57 | {
58 |
59 | protected function getTableInfo(Array &$tableColumns, Array &$tableValues)
60 | {
61 | if ($this->xmlFileContents->getName() != 'dataset') {
62 | throw new PHPUnit_Extensions_Database_Exception("The root element of a flat xml data set file must be called ");
63 | }
64 |
65 | foreach ($this->xmlFileContents->children() as $row) {
66 | $tableName = $row->getName();
67 |
68 | if (!isset($tableColumns[$tableName])) {
69 | $tableColumns[$tableName] = array();
70 | $tableValues[$tableName] = array();
71 | }
72 |
73 | $values = array();
74 | foreach ($row->attributes() as $name => $value) {
75 | if (!in_array($name, $tableColumns[$tableName])) {
76 | $tableColumns[$tableName][] = $name;
77 | }
78 |
79 | $values[$name] = $value;
80 | }
81 |
82 | if (count($values)) {
83 | $tableValues[$tableName][] = $values;
84 | }
85 | }
86 | }
87 |
88 | public static function write(PHPUnit_Extensions_Database_DataSet_IDataSet $dataset, $filename)
89 | {
90 | $pers = new PHPUnit_Extensions_Database_DataSet_Persistors_FlatXml();
91 | $pers->setFileName($filename);
92 |
93 | try {
94 | $pers->write($dataset);
95 | } catch (RuntimeException $e) {
96 | throw new PHPUnit_Framework_Exception(__METHOD__ . ' called with an unwritable file.');
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides basic functionality for table meta data.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | abstract class PHPUnit_Extensions_Database_DataSet_AbstractTableMetaData implements PHPUnit_Extensions_Database_DataSet_ITableMetaData
57 | {
58 |
59 | /**
60 | * The names of all columns in the table.
61 | *
62 | * @var Array
63 | */
64 | protected $columns;
65 |
66 | /**
67 | * The names of all the primary keys in the table.
68 | *
69 | * @var Array
70 | */
71 | protected $primaryKeys;
72 |
73 | /**
74 | * @var string
75 | */
76 | protected $tableName;
77 |
78 | /**
79 | * Returns the names of the columns in the table.
80 | *
81 | * @return array
82 | */
83 | public function getColumns()
84 | {
85 | return $this->columns;
86 | }
87 |
88 | /**
89 | * Returns the names of the primary key columns in the table.
90 | *
91 | * @return array
92 | */
93 | public function getPrimaryKeys()
94 | {
95 | return $this->primaryKeys;
96 | }
97 |
98 | /**
99 | * Returns the name of the table.
100 | *
101 | * @return string
102 | */
103 | public function getTableName()
104 | {
105 | return $this->tableName;
106 | }
107 |
108 | /**
109 | * Asserts that the given tableMetaData matches this tableMetaData.
110 | *
111 | * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $other
112 | */
113 | public function matches(PHPUnit_Extensions_Database_DataSet_ITableMetaData $other)
114 | {
115 | if ($this->getTableName() != $other->getTableName() ||
116 | $this->getColumns() != $other->getColumns()) {
117 | return FALSE;
118 | }
119 |
120 | return TRUE;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DB/IMetaData.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides a basic interface for retreiving metadata from a database.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | interface PHPUnit_Extensions_Database_DB_IMetaData
57 | {
58 | /**
59 | * Returns an array containing the names of all the tables in the database.
60 | *
61 | * @return array
62 | */
63 | public function getTableNames();
64 |
65 | /**
66 | * Returns an array containing the names of all the columns in the
67 | * $tableName table,
68 | *
69 | * @param string $tableName
70 | * @return array
71 | */
72 | public function getTableColumns($tableName);
73 |
74 | /**
75 | * Returns an array containing the names of all the primary key columns in
76 | * the $tableName table.
77 | *
78 | * @param string $tableName
79 | * @return array
80 | */
81 | public function getTablePrimaryKeys($tableName);
82 |
83 | /**
84 | * Returns the name of the default schema.
85 | *
86 | * @return string
87 | */
88 | public function getSchema();
89 |
90 | /**
91 | * Returns a quoted schema object. (table name, column name, etc)
92 | *
93 | * @param string $object
94 | * @return string
95 | */
96 | public function quoteSchemaObject($object);
97 |
98 | /**
99 | * Returns true if the rdbms allows cascading
100 | *
101 | * @return bool
102 | */
103 | public function allowsCascading();
104 |
105 | /**
106 | * Disables primary keys if rdbms does not allow setting them otherwise
107 | *
108 | * @param string $tableName
109 | */
110 | public function disablePrimaryKeys($tableName);
111 |
112 | /**
113 | * Reenables primary keys after they have been disabled
114 | *
115 | * @param string $tableName
116 | */
117 | public function enablePrimaryKeys($tableName);
118 | }
119 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/Update.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Updates the rows in a given dataset using primary key columns.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Operation_Update extends PHPUnit_Extensions_Database_Operation_RowBased
57 | {
58 |
59 | protected $operationName = 'UPDATE';
60 |
61 | protected function buildOperationQuery(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection)
62 | {
63 | $keys = $databaseTableMetaData->getPrimaryKeys();
64 | $columns = $table->getTableMetaData()->getColumns();
65 | $whereStatement = 'WHERE ' . implode(' AND ', $this->buildPreparedColumnArray($keys, $connection));
66 | $setStatement = 'SET ' . implode(', ', $this->buildPreparedColumnArray($columns, $connection));
67 |
68 | $query = "
69 | UPDATE {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())}
70 | {$setStatement}
71 | {$whereStatement}
72 | ";
73 |
74 | return $query;
75 | }
76 |
77 | protected function buildOperationArguments(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, $row)
78 | {
79 | $args = array();
80 | foreach ($table->getTableMetaData()->getColumns() as $columnName) {
81 | $args[] = $table->getValue($row, $columnName);
82 | }
83 |
84 | foreach ($databaseTableMetaData->getPrimaryKeys() as $columnName) {
85 | $args[] = $table->getValue($row, $columnName);
86 | }
87 |
88 | return $args;
89 | }
90 |
91 | protected function disablePrimaryKeys(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection)
92 | {
93 | if (count($databaseTableMetaData->getPrimaryKeys())) {
94 | return TRUE;
95 | }
96 | return FALSE;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/Exception.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Thrown for exceptions encountered with database operations. Provides
47 | * information regarding which operations failed and the query (if any) it
48 | * failed on.
49 | *
50 | * @package DbUnit
51 | * @author Mike Lively
52 | * @copyright 2010 Mike Lively
53 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
54 | * @version Release: @package_version@
55 | * @link http://www.phpunit.de/
56 | * @since Class available since Release 1.0.0
57 | */
58 | class PHPUnit_Extensions_Database_Operation_Exception extends RuntimeException
59 | {
60 |
61 | /**
62 | * @var string
63 | */
64 | protected $operation;
65 |
66 | /**
67 | * @var string
68 | */
69 | protected $preparedQuery;
70 |
71 | /**
72 | * @var array
73 | */
74 | protected $preparedArgs;
75 |
76 | /**
77 | * @var PHPUnit_Extensions_Database_DataSet_ITable
78 | */
79 | protected $table;
80 |
81 | /**
82 | * @var string
83 | */
84 | protected $error;
85 |
86 | /**
87 | * Creates a new dbunit operation exception
88 | *
89 | * @param string $operation
90 | * @param string $current_query
91 | * @param PHPUnit_Extensions_Database_DataSet_ITable $current_table
92 | * @param string $error
93 | */
94 | public function __construct($operation, $current_query, $current_args, $current_table, $error)
95 | {
96 | parent::__construct("{$operation} operation failed on query: {$current_query} using args: " . print_r($current_args, TRUE) . " [{$error}]");
97 |
98 | $this->operation = $operation;
99 | $this->preparedQuery = $current_query;
100 | $this->preparedArgs = $current_args;
101 | $this->table = $current_table;
102 | $this->error = $error;
103 | }
104 |
105 | public function getOperation()
106 | {
107 | return $this->operation;
108 | }
109 |
110 | public function getQuery()
111 | {
112 | return $this->preparedQuery;
113 | }
114 |
115 | public function getTable()
116 | {
117 | return $this->table;
118 | }
119 |
120 | public function getArgs()
121 | {
122 | return $this->preparedArgs;
123 | }
124 |
125 | public function getError()
126 | {
127 | return $this->error;
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Specs/DbTable.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Creates a database dataset based off of a spec string.
47 | *
48 | * This spec class requires a list of databases to be set to the object before
49 | * it can return a list of databases.
50 | *
51 | * The format of the spec string is as follows:
52 | *
53 | * ::
54 | *
55 | * The db label should be equal to one of the keys in the array of databases
56 | * passed to setDatabases().
57 | *
58 | * The schema should be the primary schema you will be choosing tables from.
59 | *
60 | * The tables should be a comma delimited list of all tables you would like to
61 | * pull data from.
62 | *
63 | * The sql is the query you want to use to generate the table columns and data.
64 | * The column names in the table will be identical to the column aliases in the
65 | * query.
66 | *
67 | * @package DbUnit
68 | * @author Mike Lively
69 | * @copyright 2010 Mike Lively
70 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
71 | * @version Release: @package_version@
72 | * @link http://www.phpunit.de//**
73 | * @since Class available since Release 1.0.0
74 | */
75 | class PHPUnit_Extensions_Database_DataSet_Specs_DbTable implements PHPUnit_Extensions_Database_DataSet_ISpec, PHPUnit_Extensions_Database_IDatabaseListConsumer
76 | {
77 | /**
78 | * @var array
79 | */
80 | protected $databases = array();
81 |
82 | /**
83 | * Sets the database for the spec
84 | *
85 | * @param array $databases
86 | */
87 | public function setDatabases(array $databases)
88 | {
89 | $this->databases = $databases;
90 | }
91 |
92 | /**
93 | * Creates a DB Data Set from a data set spec.
94 | *
95 | * @param string $dataSetSpec
96 | * @return PHPUnit_Extensions_Database_DataSet_IDataSet
97 | */
98 | public function getDataSet($dataSetSpec)
99 | {
100 | list($dbLabel, $schema, $tables) = explode(':', $dataSetSpec, 3);
101 | $databaseInfo = $this->databases[$dbLabel];
102 |
103 | $pdoRflc = new ReflectionClass('PDO');
104 | $pdo = $pdoRflc->newInstanceArgs(explode('|', $databaseInfo));
105 | $dbConnection = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($pdo, $schema);
106 |
107 | return !empty($tables) ? $dbConnection->createDataSet(explode(',', $tables)) : $dbConnection->createDataSet();
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/DefaultTable.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides default table functionality.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DataSet_DefaultTable extends PHPUnit_Extensions_Database_DataSet_AbstractTable
57 | {
58 |
59 | /**
60 | * Creates a new table object using the given $tableMetaData
61 | *
62 | * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData
63 | */
64 | public function __construct(PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData)
65 | {
66 | $this->setTableMetaData($tableMetaData);
67 | $this->data = array();
68 | }
69 |
70 | /**
71 | * Adds a row to the table with optional values.
72 | *
73 | * @param array $values
74 | */
75 | public function addRow($values = array())
76 | {
77 | $this->data[] = array_merge(
78 | array_fill_keys($this->getTableMetaData()->getColumns(), NULL),
79 | $values
80 | );
81 | }
82 |
83 | /**
84 | * Adds the rows in the passed table to the current table.
85 | *
86 | * @param PHPUnit_Extensions_Database_DataSet_ITable $table
87 | */
88 | public function addTableRows(PHPUnit_Extensions_Database_DataSet_ITable $table)
89 | {
90 | $tableColumns = $this->getTableMetaData()->getColumns();
91 | $rowCount = $table->getRowCount();
92 |
93 | for ($i = 0; $i < $rowCount; $i++) {
94 | $newRow = array();
95 | foreach ($tableColumns as $columnName) {
96 | $newRow[$columnName] = $table->getValue($i, $columnName);
97 | }
98 | $this->addRow($newRow);
99 | }
100 | }
101 |
102 | /**
103 | * Sets the specified column of the specied row to the specified value.
104 | *
105 | * @param int $row
106 | * @param string $column
107 | * @param mixed $value
108 | */
109 | public function setValue($row, $column, $value)
110 | {
111 | if (isset($this->data[$row])) {
112 | $this->data[$row][$column] = $value;
113 | } else {
114 | throw new InvalidArgumentException("The row given does not exist.");
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Operation/Insert.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * This class provides functionality for inserting rows from a dataset into a database.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Operation_Insert extends PHPUnit_Extensions_Database_Operation_RowBased
57 | {
58 |
59 | protected $operationName = 'INSERT';
60 |
61 | protected function buildOperationQuery(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection)
62 | {
63 | $columnCount = count($table->getTableMetaData()->getColumns());
64 |
65 | if ($columnCount > 0) {
66 | $placeHolders = implode(', ', array_fill(0, $columnCount, '?'));
67 |
68 | $columns = '';
69 | foreach ($table->getTableMetaData()->getColumns() as $column) {
70 | $columns .= $connection->quoteSchemaObject($column).', ';
71 | }
72 |
73 | $columns = substr($columns, 0, -2);
74 |
75 | $query = "
76 | INSERT INTO {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())}
77 | ({$columns})
78 | VALUES
79 | ({$placeHolders})
80 | ";
81 |
82 | return $query;
83 | } else {
84 | return FALSE;
85 | }
86 | }
87 |
88 | protected function buildOperationArguments(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, $row)
89 | {
90 | $args = array();
91 | foreach ($table->getTableMetaData()->getColumns() as $columnName) {
92 | $args[] = $table->getValue($row, $columnName);
93 | }
94 | return $args;
95 | }
96 |
97 | protected function disablePrimaryKeys(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection)
98 | {
99 | if (count($databaseTableMetaData->getPrimaryKeys())) {
100 | return TRUE;
101 | }
102 | return FALSE;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Constraint/TableIsEqual.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Asserts whether or not two dbunit tables are equal.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Constraint_TableIsEqual extends PHPUnit_Framework_Constraint
57 | {
58 | /**
59 | * @var PHPUnit_Extensions_Database_DataSet_ITable
60 | */
61 | protected $value;
62 |
63 | /**
64 | * @var string
65 | */
66 | protected $failure_reason;
67 |
68 | /**
69 | * Creates a new constraint.
70 | *
71 | * @param PHPUnit_Extensions_Database_DataSet_ITable $value
72 | */
73 | public function __construct(PHPUnit_Extensions_Database_DataSet_ITable $value)
74 | {
75 | $this->value = $value;
76 | }
77 |
78 | /**
79 | * Evaluates the constraint for parameter $other. Returns TRUE if the
80 | * constraint is met, FALSE otherwise.
81 | *
82 | * This method can be overridden to implement the evaluation algorithm.
83 | *
84 | * @param mixed $other Value or object to evaluate.
85 | * @return bool
86 | */
87 | protected function matches($other)
88 | {
89 | if (!$other instanceof PHPUnit_Extensions_Database_DataSet_ITable) {
90 | throw new InvalidArgumentException(
91 | 'PHPUnit_Extensions_Database_DataSet_ITable expected'
92 | );
93 | }
94 |
95 | return $this->value->matches($other);
96 | }
97 |
98 | /**
99 | * Returns the description of the failure
100 | *
101 | * The beginning of failure messages is "Failed asserting that" in most
102 | * cases. This method should return the second part of that sentence.
103 | *
104 | * @param mixed $other Evaluated value or object.
105 | * @return string
106 | */
107 | protected function failureDescription($other)
108 | {
109 | return $other->__toString() . ' ' . $this->toString();
110 | }
111 |
112 | /**
113 | * Returns a string representation of the constraint.
114 | *
115 | * @return string
116 | */
117 | public function toString()
118 | {
119 | return sprintf(
120 | 'is equal to expected %s', $this->value->__toString()
121 | );
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Asserts whether or not two dbunit datasets are equal.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2010 Mike Lively
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_Constraint_DataSetIsEqual extends PHPUnit_Framework_Constraint
57 | {
58 | /**
59 | * @var PHPUnit_Extensions_Database_DataSet_IDataSet
60 | */
61 | protected $value;
62 |
63 | /**
64 | * @var string
65 | */
66 | protected $failure_reason;
67 |
68 | /**
69 | * Creates a new constraint.
70 | *
71 | * @param PHPUnit_Extensions_Database_DataSet_IDataSet $value
72 | */
73 | public function __construct(PHPUnit_Extensions_Database_DataSet_IDataSet $value)
74 | {
75 | $this->value = $value;
76 | }
77 |
78 | /**
79 | * Evaluates the constraint for parameter $other. Returns TRUE if the
80 | * constraint is met, FALSE otherwise.
81 | *
82 | * This method can be overridden to implement the evaluation algorithm.
83 | *
84 | * @param mixed $other Value or object to evaluate.
85 | * @return bool
86 | */
87 | protected function matches($other)
88 | {
89 | if (!$other instanceof PHPUnit_Extensions_Database_DataSet_IDataSet) {
90 | throw new InvalidArgumentException(
91 | 'PHPUnit_Extensions_Database_DataSet_IDataSet expected'
92 | );
93 | }
94 |
95 | return $this->value->matches($other);
96 | }
97 |
98 | /**
99 | * Returns the description of the failure
100 | *
101 | * The beginning of failure messages is "Failed asserting that" in most
102 | * cases. This method should return the second part of that sentence.
103 | *
104 | * @param mixed $other Evaluated value or object.
105 | * @return string
106 | */
107 | protected function failureDescription($other)
108 | {
109 | return $other->__toString() . ' ' . $this->toString();
110 | }
111 |
112 | /**
113 | * Returns a string representation of the constraint.
114 | *
115 | * @return string
116 | */
117 | public function toString()
118 | {
119 | return sprintf(
120 | 'is equal to expected %s', $this->value->__toString()
121 | );
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/ITester.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * This is the interface for DatabaseTester objects. These objects are used to
47 | * add database testing to existing test cases using composition instead of
48 | * extension.
49 | *
50 | * @package DbUnit
51 | * @author Mike Lively
52 | * @copyright 2010 Mike Lively
53 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
54 | * @version Release: @package_version@
55 | * @link http://www.phpunit.de/
56 | * @since Class available since Release 1.0.0
57 | */
58 | interface PHPUnit_Extensions_Database_ITester
59 | {
60 |
61 | /**
62 | * Closes the specified connection.
63 | *
64 | * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
65 | */
66 | public function closeConnection(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection);
67 |
68 | /**
69 | * Returns the test database connection.
70 | *
71 | * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
72 | */
73 | public function getConnection();
74 |
75 | /**
76 | * Returns the test dataset.
77 | *
78 | * @return PHPUnit_Extensions_Database_DataSet_IDataSet
79 | */
80 | public function getDataSet();
81 |
82 | /**
83 | * TestCases must call this method inside setUp().
84 | */
85 | public function onSetUp();
86 |
87 | /**
88 | * TestCases must call this method inside teadDown().
89 | */
90 | public function onTearDown();
91 |
92 | /**
93 | * Sets the test dataset to use.
94 | *
95 | * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
96 | */
97 | public function setDataSet(PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet);
98 |
99 | /**
100 | * Sets the schema value.
101 | *
102 | * @param string $schema
103 | */
104 | public function setSchema($schema);
105 |
106 | /**
107 | * Sets the DatabaseOperation to call when starting the test.
108 | *
109 | * @param PHPUnit_Extensions_Database_Operation_DatabaseOperation $setUpOperation
110 | */
111 | public function setSetUpOperation(PHPUnit_Extensions_Database_Operation_IDatabaseOperation $setUpOperation);
112 |
113 | /**
114 | * Sets the DatabaseOperation to call when starting the test.
115 | *
116 | * @param PHPUnit_Extensions_Database_Operation_DatabaseOperation $tearDownOperation
117 | */
118 | public function setTearDownOperation(PHPUnit_Extensions_Database_Operation_IDatabaseOperation $tearDownOperation);
119 | }
120 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DataSet/Specs/DbQuery.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Creates DefaultDataSets based off of a spec string.
47 | *
48 | * This spec class requires a list of databases to be set to the object before
49 | * it can return a list of databases.
50 | *
51 | * The format of the spec string is as follows:
52 | *
53 | * :::
54 | *
55 | * The db label should be equal to one of the keys in the array of databases
56 | * passed to setDatabases().
57 | *
58 | * The schema should be the primary schema you will be running the sql query
59 | * against.
60 | *
61 | * The table name should be set to what you would like the table name in the
62 | * dataset to be.
63 | *
64 | * The sql is the query you want to use to generate the table columns and data.
65 | * The column names in the table will be identical to the column aliases in the
66 | * query.
67 | *
68 | * @package DbUnit
69 | * @author Mike Lively
70 | * @copyright 2010 Mike Lively
71 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
72 | * @version Release: @package_version@
73 | * @link http://www.phpunit.de/
74 | * @since Class available since Release 1.0.0
75 | */
76 | class PHPUnit_Extensions_Database_DataSet_Specs_DbQuery implements PHPUnit_Extensions_Database_DataSet_ISpec, PHPUnit_Extensions_Database_IDatabaseListConsumer
77 | {
78 | /**
79 | * @var array
80 | */
81 | protected $databases = array();
82 |
83 | /**
84 | * Sets the database for the spec
85 | *
86 | * @param array $databases
87 | */
88 | public function setDatabases(array $databases)
89 | {
90 | $this->databases = $databases;
91 | }
92 |
93 | /**
94 | * Creates a Default Data Set with a query table from a data set spec.
95 | *
96 | * @param string $dataSetSpec
97 | * @return PHPUnit_Extensions_Database_DataSet_DefaultDataSet
98 | */
99 | public function getDataSet($dataSetSpec)
100 | {
101 | list($dbLabel, $schema, $table, $sql) = explode(':', $dataSetSpec, 4);
102 | $databaseInfo = $this->databases[$dbLabel];
103 |
104 | $pdoRflc = new ReflectionClass('PDO');
105 | $pdo = $pdoRflc->newInstanceArgs(explode('|', $databaseInfo));
106 | $dbConnection = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($pdo, $schema);
107 | $table = $dbConnection->createQueryTable($table, $sql);
108 |
109 | return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table));
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/PHPUnit/Extensions/Database/DB/MetaData/MySQL.php:
--------------------------------------------------------------------------------
1 | .
6 | * All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright
13 | * notice, this list of conditions and the following disclaimer.
14 | *
15 | * * Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in
17 | * the documentation and/or other materials provided with the
18 | * distribution.
19 | *
20 | * * Neither the name of Sebastian Bergmann nor the names of his
21 | * contributors may be used to endorse or promote products derived
22 | * from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | * POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * @package DbUnit
38 | * @author Mike Lively
39 | * @copyright 2002-2012 Sebastian Bergmann
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 | * @link http://www.phpunit.de/
42 | * @since File available since Release 1.0.0
43 | */
44 |
45 | /**
46 | * Provides functionality to retrieve meta data from a MySQL database.
47 | *
48 | * @package DbUnit
49 | * @author Mike Lively
50 | * @copyright 2002-2012 Sebastian Bergmann
51 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
52 | * @version Release: @package_version@
53 | * @link http://www.phpunit.de/
54 | * @since Class available since Release 1.0.0
55 | */
56 | class PHPUnit_Extensions_Database_DB_MetaData_MySQL extends PHPUnit_Extensions_Database_DB_MetaData
57 | {
58 | protected $schemaObjectQuoteChar = '`';
59 |
60 | /**
61 | * Returns an array containing the names of all the tables in the database.
62 | *
63 | * @return array
64 | */
65 | public function getTableNames()
66 | {
67 | $query = 'SHOW TABLES';
68 | $statement = $this->pdo->prepare($query);
69 | $statement->execute();
70 |
71 | $tableNames = array();
72 | while (($tableName = $statement->fetchColumn(0))) {
73 | $tableNames[] = $tableName;
74 | }
75 |
76 | return $tableNames;
77 | }
78 |
79 | /**
80 | * Returns an array containing the names of all the columns in the
81 | * $tableName table,
82 | *
83 | * @param string $tableName
84 | * @return array
85 | */
86 | public function getTableColumns($tableName)
87 | {
88 | $query = 'SHOW COLUMNS FROM ' . $this->quoteSchemaObject($tableName);
89 | $statement = $this->pdo->prepare($query);
90 | $statement->execute();
91 |
92 | $columnNames = array();
93 | while (($columnName = $statement->fetchColumn(0))) {
94 | $columnNames[] = $columnName;
95 | }
96 |
97 | return $columnNames;
98 | }
99 |
100 | /**
101 | * Returns an array containing the names of all the primary key columns in
102 | * the $tableName table.
103 | *
104 | * @param string $tableName
105 | * @return array
106 | */
107 | public function getTablePrimaryKeys($tableName)
108 | {
109 | $query = 'SHOW INDEX FROM ' . $this->quoteSchemaObject($tableName);
110 | $statement = $this->pdo->prepare($query);
111 | $statement->execute();
112 | $statement->setFetchMode(PDO::FETCH_ASSOC);
113 |
114 | $columnNames = array();
115 | while (($column = $statement->fetch())) {
116 | if ($column['Key_name'] == 'PRIMARY') {
117 | $columnNames[] = $column['Column_name'];
118 | }
119 | }
120 |
121 | return $columnNames;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------