Page MenuHomeDevCentral

D3760.id.diff
No OneTemporary

D3760.id.diff

diff --git a/.gitignore b/.gitignore
new file mode 100644
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+# PHPUnit
+.phpunit.result.cache
+.phpunit.cache/
diff --git a/workspaces/tests/phpunit.xml b/phpunit.xml
copy from workspaces/tests/phpunit.xml
copy to phpunit.xml
--- a/workspaces/tests/phpunit.xml
+++ b/phpunit.xml
@@ -1,9 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
<phpunit
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
-
- forceCoversAnnotation="true"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd"
+ bootstrap="vendor/autoload.php"
+ displayDetailsOnTestsThatTriggerDeprecations="true"
+ displayDetailsOnPhpunitDeprecations="true"
+ cacheDirectory=".phpunit.cache"
+ stopOnFailure="false"
>
+
+ <testsuites>
+ <testsuite name="Unit tests for waystone/workspaces">
+ <directory suffix="Test.php">workspaces/tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <source>
+ <include>
+ <directory suffix=".php">workspaces/src/</directory>
+ </include>
+ </source>
+
<php>
<!-- MySQL -->
<const name="UNITTESTING_MYSQL_HOST" value="localhost" />
diff --git a/workspaces/tests/Engines/Collection/BookDocument.php b/workspaces/tests/Engines/Collection/BookDocument.php
new file mode 100644
--- /dev/null
+++ b/workspaces/tests/Engines/Collection/BookDocument.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Waystone\Workspaces\Tests\Engines\Collection;
+
+use CollectionDocument;
+
+require_once(__DIR__ . '/../../../src/includes/autoload.php');
+
+/**
+ * A CollectionDocument class, for our tests.
+ */
+class BookDocument extends CollectionDocument {
+ /**
+ * @var string The book title
+ */
+ public $title;
+
+ /**
+ * @var string The book author
+ */
+ public $author;
+
+ /**
+ * Initializes a new instance of the BookDocument object
+ */
+ public function __construct ($author = null, $title = null) {
+ if ($title !== null) $this->title = $title;
+ if ($author !== null) $this->author = $author;
+ }
+}
diff --git a/workspaces/tests/includes/collection/CRUDTestTrait.php b/workspaces/tests/Engines/Collection/CRUDTestTrait.php
rename from workspaces/tests/includes/collection/CRUDTestTrait.php
rename to workspaces/tests/Engines/Collection/CRUDTestTrait.php
--- a/workspaces/tests/includes/collection/CRUDTestTrait.php
+++ b/workspaces/tests/Engines/Collection/CRUDTestTrait.php
@@ -15,30 +15,9 @@
* @filesource
*/
-require_once('../src/includes/autoload.php');
+namespace Waystone\Workspaces\Tests\Engines\Collection;
-/**
- * A CollectionDocument class, for our tests.
- */
-class BookDocument extends CollectionDocument {
- /**
- * @var string The book title
- */
- public $title;
-
- /**
- * @var string The book author
- */
- public $author;
-
- /**
- * Initializes a new instance of the BookDocument object
- */
- public function __construct ($author = null, $title = null) {
- if ($title !== null) $this->title = $title;
- if ($author !== null) $this->author = $author;
- }
-}
+use CollectionDocument;
/**
* The tests for our basic, non storage engine specific CRUD features
@@ -136,16 +115,16 @@
//::get - when our collection uses the generic CollectionDocument class
$newDocument = $this->collection->get($this->redBook->id);
- $this->assertInstanceOf('CollectionDocument', $newDocument);
- $this->assertNotInstanceOf('BookDocument', $newDocument);
+ $this->assertInstanceOf(CollectionDocument::class, $newDocument);
+ $this->assertNotInstanceOf(BookDocument::class, $newDocument);
//::set - when our collection uses a proper CollectionDocument descendant
- $this->collection->documentType = 'BookDocument';
+ $this->collection->documentType = BookDocument::class;
$newBook = $this->collection->get($this->redBook->id);
- $this->assertInstanceOf('BookDocument', $newBook);
- $this->assertObjectHasAttribute('title', $newBook);
- $this->assertObjectHasAttribute('author', $newBook);
- $this->assertObjectHasAttribute('id', $newBook);
+ $this->assertInstanceOf(BookDocument::class, $newBook);
+ $this->assertObjectHasProperty('title', $newBook);
+ $this->assertObjectHasProperty('author', $newBook);
+ $this->assertObjectHasProperty('id', $newBook);
$this->assertEquals('Matter', $newBook->title);
$this->assertEquals('Iain M. Banks', $newBook->author);
$this->assertEquals('redBook', $newBook->id);
@@ -182,19 +161,19 @@
foreach ($documents as $document) {
switch ($document->id) {
case $this->blueBook->id:
- $this->assertInstanceOf('BookDocument', $document);
- $this->assertObjectHasAttribute('title', $document);
- $this->assertObjectHasAttribute('author', $document);
- $this->assertObjectHasAttribute('id', $document);
+ $this->assertInstanceOf(BookDocument::class, $document);
+ $this->assertObjectHasProperty('title', $document);
+ $this->assertObjectHasProperty('author', $document);
+ $this->assertObjectHasProperty('id', $document);
$this->assertEquals('Foundation', $document->title);
$this->assertEquals('Isaac Asimov', $document->author);
break;
case 'redBook':
- $this->assertInstanceOf('BookDocument', $document);
- $this->assertObjectHasAttribute('title', $document);
- $this->assertObjectHasAttribute('author', $document);
- $this->assertObjectHasAttribute('id', $document);
+ $this->assertInstanceOf(BookDocument::class, $document);
+ $this->assertObjectHasProperty('title', $document);
+ $this->assertObjectHasProperty('author', $document);
+ $this->assertObjectHasProperty('id', $document);
$this->assertEquals('Matter', $document->title);
$this->assertEquals('Iain M. Banks', $document->author);
break;
@@ -230,6 +209,7 @@
//::getAll
$documents = $this->collection->getAll();
- $this->assertCount(0, $documents, "We expected each collection document would have been deleted.");
+ $count = iterator_count($documents);
+ $this->assertEquals(0, $count, "We expected each collection document would have been deleted.");
}
}
diff --git a/workspaces/tests/includes/collection/FilesCollectionTest.php b/workspaces/tests/Engines/Collection/FilesCollectionTest.php
rename from workspaces/tests/includes/collection/FilesCollectionTest.php
rename to workspaces/tests/Engines/Collection/FilesCollectionTest.php
--- a/workspaces/tests/includes/collection/FilesCollectionTest.php
+++ b/workspaces/tests/Engines/Collection/FilesCollectionTest.php
@@ -15,14 +15,23 @@
* @filesource
*/
-require_once('CRUDTestTrait.php');
-require('../src/includes/GlobalFunctions.php');
+namespace Waystone\Workspaces\Tests\Engines\Collection;
+
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\TestCase;
+
+use FilesCollection;
+
+use Exception;
+
+require_once(__DIR__ . '/../../../src//includes/GlobalFunctions.php');
/**
* Tests FilesCollection class
- * @coversDefaultClass FilesCollection
*/
-class FilesCollectionTest extends PHPUnit_Framework_TestCase {
+#[CoversClass(FilesCollection::class)]
+class FilesCollectionTest extends TestCase {
+
/**
* @var string Our collection
*/
@@ -42,14 +51,7 @@
];
}
- /**
- * Initializes a new instance of the PHPUnit_Framework_TestCase class
- *
- * @param string $name The test case name
- */
- public function __construct (string $name = null) {
- parent::__construct($name);
-
+ protected function setUp () : void {
$this->initializeDocuments();
global $Config;
@@ -57,14 +59,9 @@
$this->collection = new FilesCollection('quux');
}
-
///
/// Specific tests for this particular Collection class
///
-
- /**
- * @covers FilesCollection::__construct
- */
public function testConstructor () {
global $Config;
$Config = self::getConfig();
@@ -73,17 +70,13 @@
$this->assertEquals('quux', $collection->id);
}
- /**
- * @covers FilesCollection::getCollectionPath
- * @covers FilesCollection::getDocumentPath
- */
public function testPaths () {
global $Config;
$Config = self::getConfig();
$expectedPath = UNITTESTING_FILESCOLLECTION_PATH
- . DIRECTORY_SEPARATOR
- . 'quux';
+ . DIRECTORY_SEPARATOR
+ . 'quux';
$this->assertEquals(
$expectedPath,
@@ -93,50 +86,38 @@
$this->assertFileExists($expectedPath);
$expectedPath .= DIRECTORY_SEPARATOR
- . 'foo.json';
+ . 'foo.json';
$this->assertEquals(
$expectedPath,
$this->collection->getDocumentPath('foo')
);
}
- /**
- * @covers FilesCollection::getCollectionPath
- */
public function testConfigurationMissingException () {
//Note: @expectedException isn't allowed in PHPUnit to test the generic Exception class.
global $Config;
$oldConfigDocumentStorage = $Config['DocumentStorage'];
$Config['DocumentStorage'] = []; //Path isn't defined
- try {
- FilesCollection::getCollectionPath('quux');
- } catch (Exception $ex) {
- $Config['DocumentStorage'] = $oldConfigDocumentStorage;
- return;
- }
- $this->fail('An expected exception has not been raised.');
+
+ $this>$this->expectException(Exception::class);
+ FilesCollection::getCollectionPath('quux');
+
+ $Config['DocumentStorage'] = $oldConfigDocumentStorage;
}
- /**
- * @covers FilesCollection::getCollectionPath
- */
public function testCantCreateDirectoryException () {
- //Note: @expectedException isn't allowed in PHPUnit to test the generic Exception class.
-
global $Config;
$oldConfigDocumentStorage = $Config['DocumentStorage'];
$Config['DocumentStorage'] = [
'Type' => 'Files',
'Path' => '/root/obsidiancollections',
];
- try {
- FilesCollection::getCollectionPath('quux');
- } catch (Exception $ex) {
- $Config['DocumentStorage'] = $oldConfigDocumentStorage;
- return;
- }
- $this->fail("An expected exception has not been raised. If you're logged as root, you can safely delete /root/obsidiancollections folder and ignore this test. By the way, are you sure to trust a tests sequence creating and deleting files to run them as root?");
+
+ $this->expectException(Exception::class);
+ FilesCollection::getCollectionPath('quux');
+
+ $Config['DocumentStorage'] = $oldConfigDocumentStorage;
}
///
@@ -145,10 +126,6 @@
use CRUDTestTrait;
- /**
- * @covers FilesCollection::add
- * @covers FilesCollection::update
- */
public function testFileContent () {
global $Config;
$Config = self::getConfig();
@@ -184,7 +161,7 @@
/**
* Tears down resources when tests are done
*/
- public static function tearDownAfterClass () {
+ public static function tearDownAfterClass () : void {
//Removes created directories
rmdir(UNITTESTING_FILESCOLLECTION_PATH . '/quux');
rmdir(UNITTESTING_FILESCOLLECTION_PATH);
diff --git a/workspaces/tests/includes/collection/MongoDBCollectionTest.php b/workspaces/tests/Engines/Collection/MongoDBCollectionTest.php
rename from workspaces/tests/includes/collection/MongoDBCollectionTest.php
rename to workspaces/tests/Engines/Collection/MongoDBCollectionTest.php
--- a/workspaces/tests/includes/collection/MongoDBCollectionTest.php
+++ b/workspaces/tests/Engines/Collection/MongoDBCollectionTest.php
@@ -15,13 +15,18 @@
* @filesource
*/
-require_once('CRUDTestTrait.php');
+namespace Waystone\Workspaces\Tests\Engines\Collection;
+
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\TestCase;
+
+use MongoDBCollection;
/**
* Tests MongoDBCollection class
- * @coversDefaultClass MongoDBCollection
*/
-class MongoDBCollectionTest extends PHPUnit_Framework_TestCase {
+#[CoversClass(MongoDBCollection::class)]
+class MongoDBCollectionTest extends TestCase {
/**
* @var string Our collection
*/
@@ -43,14 +48,7 @@
];
}
- /**
- * Initializes a new instance of the PHPUnit_Framework_TestCase class
- *
- * @param string $name The test case name
- */
- public function __construct (string $name = null) {
- parent::__construct($name);
-
+ public function setUp () : void {
global $Config;
$Config = static::getConfig();
diff --git a/workspaces/tests/includes/collection/MySQCollectionTest.php b/workspaces/tests/Engines/Collection/MySQCollectionTest.php
rename from workspaces/tests/includes/collection/MySQCollectionTest.php
rename to workspaces/tests/Engines/Collection/MySQCollectionTest.php
--- a/workspaces/tests/includes/collection/MySQCollectionTest.php
+++ b/workspaces/tests/Engines/Collection/MySQCollectionTest.php
@@ -15,14 +15,18 @@
* @filesource
*/
-require_once('CRUDTestTrait.php');
-require_once('SQLTestTrait.php');
+namespace Waystone\Workspaces\Tests\Engines\Collection;
+
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\TestCase;
+
+use MySQLCollection;
/**
* Tests MySQLCollection class
- * @coversDefaultClass MySQLCollection
*/
-class MySQLCollectionTest extends PHPUnit_Framework_TestCase {
+#[CoversClass(MySQLCollection::class)]
+class MySQLCollectionTest extends TestCase {
///
/// Traits
///
@@ -60,7 +64,7 @@
/**
* Initializes the resources needed for thist test.
*/
- public function setUp () {
+ public function setUp () : void {
$db = new MySQLDatabase(
UNITTESTING_MYSQL_HOST,
UNITTESTING_MYSQL_USERNAME,
@@ -78,8 +82,6 @@
/**
* Tests the property table is correctly set
- *
- * @covers MySQLCollection::construct
*/
public function testTable () {
$this->assertEquals(UNITTESTING_MYSQL_TABLE, $this->collection->table, "The collection constructor should have initialized the MySQLCollection::table property.");
@@ -87,8 +89,6 @@
/**
* Tests if the ready constant has been correctly defined
- *
- * @covers MySQLCollection::initializeCollectionsTable
*/
public function testReadyConstant () {
$this->assertTrue(
@@ -105,8 +105,6 @@
/**
* Tests if strings are correctly escaped
- *
- * @covers MySQLCollection::escape
*/
public function testEscape () {
$toEscapeExpressions = [
diff --git a/workspaces/tests/includes/collection/SQLTestTrait.php b/workspaces/tests/Engines/Collection/SQLTestTrait.php
rename from workspaces/tests/includes/collection/SQLTestTrait.php
rename to workspaces/tests/Engines/Collection/SQLTestTrait.php
--- a/workspaces/tests/includes/collection/SQLTestTrait.php
+++ b/workspaces/tests/Engines/Collection/SQLTestTrait.php
@@ -15,7 +15,9 @@
* @filesource
*/
-require_once('../src/includes/autoload.php');
+namespace Waystone\Workspaces\Tests\Engines\Collection;
+
+require_once(__DIR__ . '/../../../src/includes/autoload.php');
/**
* The tests for our SQL storage engines, to ensure the schema is created correctly.
@@ -63,4 +65,4 @@
];
$this->assertEquals($expectedResultArray, $resultArray, "The query() specifications provides: '[If the query returns a non scalar result, return] an associative array, the fields as keys, the row as values.'. This is expected for $sqlArrayResult.");
}
-}
\ No newline at end of file
+}
diff --git a/workspaces/tests/includes/collection/SQLiteCollectionTest.php b/workspaces/tests/Engines/Collection/SQLiteCollectionTest.php
rename from workspaces/tests/includes/collection/SQLiteCollectionTest.php
rename to workspaces/tests/Engines/Collection/SQLiteCollectionTest.php
--- a/workspaces/tests/includes/collection/SQLiteCollectionTest.php
+++ b/workspaces/tests/Engines/Collection/SQLiteCollectionTest.php
@@ -15,14 +15,18 @@
* @filesource
*/
-require_once('CRUDTestTrait.php');
-require_once('SQLTestTrait.php');
+namespace Waystone\Workspaces\Tests\Engines\Collection;
+
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\TestCase;
+
+use SQLiteCollection;
/**
* Tests SQLiteCollection class
- * @coversDefaultClass SQLiteCollection
*/
-class SQLiteCollectionTest extends PHPUnit_Framework_TestCase {
+#[CoversClass(SQLiteCollection::class)]
+class SQLiteCollectionTest extends TestCase {
///
/// Traits
///
@@ -57,14 +61,7 @@
];
}
- /**
- * Initializes a new instance of the PHPUnit_Framework_TestCase class
- *
- * @param string $name The test case name
- */
- public function __construct (string $name = null) {
- parent::__construct($name);
-
+ public function setUp () : void {
$this->initializeDocuments();
global $Config;
@@ -76,13 +73,8 @@
///
/// Tests specific to SQLiteCollection
///
-
/**
* Tests the client related methods
- *
- * @covers SQLiteCollection::getClient
- * @covers SQLiteCollection::initializeClient
- * @covers SQLiteCollection::initializeCollectionsTable
*/
public function testClient () {
global $Config;
@@ -118,8 +110,6 @@
/**
* Tests string escapement
- *
- * @covers SQLiteCollection::escape
*/
public function testEscape () {
$toEscapeExpressions = [
@@ -146,9 +136,6 @@
}
}
- /**
- * @covers SQLiteCollection::isStatement
- */
public function testStatements () {
$sqlQueries = [
"SELECT foo FROM bar",
@@ -181,7 +168,7 @@
/**
* Clears resources created for this test
*/
- public static function tearDownAfterClass () {
+ public static function tearDownAfterClass () : void {
unlink(UNITTESTING_SQLITE_FILE);
}
}
diff --git a/workspaces/tests/includes/collection/greenBook1.json b/workspaces/tests/Engines/Collection/greenBook1.json
rename from workspaces/tests/includes/collection/greenBook1.json
rename to workspaces/tests/Engines/Collection/greenBook1.json
diff --git a/workspaces/tests/includes/collection/greenBook2.json b/workspaces/tests/Engines/Collection/greenBook2.json
rename from workspaces/tests/includes/collection/greenBook2.json
rename to workspaces/tests/Engines/Collection/greenBook2.json
diff --git a/workspaces/tests/bootstrap.php b/workspaces/tests/bootstrap.php
new file mode 100644
--- /dev/null
+++ b/workspaces/tests/bootstrap.php
@@ -0,0 +1,53 @@
+<?php
+
+/* -------------------------------------------------------------
+ Bootstrap tests for Obsidian Workspaces
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ Project: Nasqueron
+ Product: Obsidian Workspaces
+ License: Trivial work, not eligible to copyright
+ ------------------------------------------------------------- */
+
+/* -------------------------------------------------------------
+ Search relevant vendor/ directory
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+const VENDOR_DIR_CANDIDATES = [
+ # Composer packages have been installed directly in workspaces/
+ __DIR__ . "/../vendor",
+
+ # Composer packages have been installed at monorepo root level
+ __DIR__ . "/../../vendor",
+
+];
+
+function search_vendor_autoload () : string|null {
+ foreach (VENDOR_DIR_CANDIDATES as $dir) {
+ $autoload_path = $dir . "/autoload.php";
+
+ echo "Candidate: $autoload_path\n";
+
+ if (file_exists($autoload_path)) {
+ return $autoload_path;
+ }
+ }
+
+ return null;
+}
+
+/* -------------------------------------------------------------
+ Entry point for tests
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+function run() : void {
+ $vendor_autoload = search_vendor_autoload();
+
+ if ($vendor_autoload === null) {
+ fwrite(STDERR, "Your first need to install dependencies. Run `composer install` before running tests.");
+ die;
+ }
+
+ require($vendor_autoload);
+}
+
+run();
diff --git a/workspaces/tests/includes/database/DatabaseExceptionTest.php b/workspaces/tests/includes/database/DatabaseExceptionTest.php
--- a/workspaces/tests/includes/database/DatabaseExceptionTest.php
+++ b/workspaces/tests/includes/database/DatabaseExceptionTest.php
@@ -15,16 +15,14 @@
* @filesource
*/
-require '../src/includes/database/DatabaseException.php';
+use PHPUnit\Framework\TestCase;
+
+require_once(__DIR__ . '/../../../src/includes/database/DatabaseException.php');
/**
* Tests DatabaseException class
*/
-class DatabaseExceptionTest extends PHPUnit_Framework_TestCase {
- /**
- * @covers DatabaseException::__construct
- * @covers DatabaseException::getQuery
- */
+class DatabaseExceptionTest extends TestCase {
public function testGetQuery () {
$sql = 'SELECT 1+';
$ex = new DatabaseException($sql, 'Syntax error', 1064);
diff --git a/workspaces/tests/includes/database/MySQLDatabaseTest.php b/workspaces/tests/includes/database/MySQLDatabaseTest.php
--- a/workspaces/tests/includes/database/MySQLDatabaseTest.php
+++ b/workspaces/tests/includes/database/MySQLDatabaseTest.php
@@ -15,12 +15,14 @@
* @filesource
*/
+use PHPUnit\Framework\TestCase;
+
//require '../src/includes/database/MysqlDatabase.php';
/**
* Tests DatabaseTest
*/
-class MySQLDatabaseTest extends PHPUnit_Framework_TestCase {
+class MySQLDatabaseTest extends TestCase {
/**
* @var MysqlDatabase
*/
@@ -29,7 +31,7 @@
/**
* Creates the objects against which we will test.
*/
- public function setUp () {
+ public function setUp () : void {
$this->db = new MySQLDatabase(
UNITTESTING_MYSQL_HOST,
UNITTESTING_MYSQL_USERNAME,
@@ -40,8 +42,6 @@
/**
* Tests string escape
- *
- * @covers SQLiteCollection::escape
*/
public function testEscape () {
$toEscapeExpressions = [
diff --git a/workspaces/tests/phpunit.xml b/workspaces/tests/phpunit.xml
--- a/workspaces/tests/phpunit.xml
+++ b/workspaces/tests/phpunit.xml
@@ -1,8 +1,10 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
+ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd"
+ bootstrap="bootstrap.php"
- forceCoversAnnotation="true"
+ displayDetailsOnTestsThatTriggerDeprecations="true"
+ displayDetailsOnPhpunitDeprecations="true"
>
<php>
<!-- MySQL -->

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 20, 09:35 (20 h, 54 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3089090
Default Alt Text
D3760.id.diff (23 KB)

Event Timeline