From eb1b8dd8336a0bbfc87e1be0dfd6283ccbe7449c Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 20 Nov 2018 06:29:09 -0500 Subject: [PATCH] Test DB schema update --- .gitignore | 3 ++- composer.json | 2 +- src/ActivityPub.php | 2 +- src/Entities/IndexEntity.php | 5 +++-- test/ActivityPubTest.php | 25 +++++++++++++++++++++--- test/{Config => config}/APTestCase.php | 2 +- test/{Config => config}/ArrayDataSet.php | 0 test/{Config => config}/bootstrap.php | 0 test/config/config.xml | 2 ++ 9 files changed, 32 insertions(+), 9 deletions(-) rename test/{Config => config}/APTestCase.php (95%) rename test/{Config => config}/ArrayDataSet.php (100%) rename test/{Config => config}/bootstrap.php (100%) create mode 100644 test/config/config.xml diff --git a/.gitignore b/.gitignore index a725465..8af3c9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -vendor/ \ No newline at end of file +vendor/ +test/db.sqlite \ No newline at end of file diff --git a/composer.json b/composer.json index f5c0034..bfefe5b 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "scripts": { - "test": "phpunit --bootstrap ./test/Config/bootstrap.php test" + "test": "phpunit -c ./test/config/config.xml test" }, "repositories": [ { diff --git a/src/ActivityPub.php b/src/ActivityPub.php index 326ca75..9436f69 100644 --- a/src/ActivityPub.php +++ b/src/ActivityPub.php @@ -16,7 +16,7 @@ class ActivityPub * Constructs a new ActivityPub instance * * @param array $opts Array of options. Valid keys are - * 'dbuser', 'dbpass', 'dbname', 'dbprefix', and 'isDevMode'. + * 'dbOptions', 'dbprefix', and 'isDevMode'. */ public function __construct( $opts ) { diff --git a/src/Entities/IndexEntity.php b/src/Entities/IndexEntity.php index 01763be..cb6b598 100644 --- a/src/Entities/IndexEntity.php +++ b/src/Entities/IndexEntity.php @@ -12,11 +12,12 @@ namespace ActivityPub\Entities; * is a static value, like { "url": "https://example.com" }. An object is another foreign * key into the objects table that represents the value of the JSON-LD field if the * field is another JSON-LD object, like { "inReplyTo": { assertTrue( file_exists( $this->dbPath ) ); + $this->assertTrue( file_exists( $this->getDbPath() ) ); + } + + /** + * @depends testItCreatesSchema + */ + public function testItUpdatesSchema() { + $activityPub = new ActivityPub(array( + 'dbOptions' => array( + 'driver' => 'pdo_sqlite', + 'path' => $this->getDbPath(), + ), + ) ); + $activityPub->updateSchema(); + $this->assertTrue( file_exists( $this->getDbPath() ) ); + } + + private function getDbPath() { + return dirname( __FILE__ ) . '/db.sqlite'; } } ?> diff --git a/test/Config/APTestCase.php b/test/config/APTestCase.php similarity index 95% rename from test/Config/APTestCase.php rename to test/config/APTestCase.php index 67b8556..51a888b 100644 --- a/test/Config/APTestCase.php +++ b/test/config/APTestCase.php @@ -10,7 +10,7 @@ abstract class APTestCase extends TestCase private static $pdo = null; private $conn = null; - protected $dbPath = ''; + private $dbPath = ''; final public function getConnection() { if ( $this->conn === null ) { diff --git a/test/Config/ArrayDataSet.php b/test/config/ArrayDataSet.php similarity index 100% rename from test/Config/ArrayDataSet.php rename to test/config/ArrayDataSet.php diff --git a/test/Config/bootstrap.php b/test/config/bootstrap.php similarity index 100% rename from test/Config/bootstrap.php rename to test/config/bootstrap.php diff --git a/test/config/config.xml b/test/config/config.xml new file mode 100644 index 0000000..a070a56 --- /dev/null +++ b/test/config/config.xml @@ -0,0 +1,2 @@ + +