Skip to content

Commit

Permalink
Merge pull request alcaeus#272 from alcaeus/phpunit-bridge
Browse files Browse the repository at this point in the history
Use PHPUnit bridge to test on multiple PHP versions
  • Loading branch information
alcaeus authored Oct 16, 2020
2 parents 17f31ff + 5808354 commit 3e1d2b0
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
composer.lock
.phpcs-cache
.phpunit.result.cache
vendor/
tests/scripts/
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- 7.4

env:
global:
Expand All @@ -29,23 +29,23 @@ before_install:
- composer update ${COMPOSER_FLAGS}

script:
- vendor/bin/phpunit
- vendor/bin/simple-phpunit

jobs:
include:
# Run tests with coverage
- stage: test
php: 7.3
script:
- vendor/bin/phpunit --coverage-clover=coverage.clover
- vendor/bin/simple-phpunit --coverage-clover=coverage.clover
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

# Test against legacy driver to ensure validity of the test suite
- stage: Test
php: 5.6
env: DRIVER_VERSION="1.7.5"
env: DRIVER_VERSION="1.7.5" SYMFONY_DEPRECATIONS_HELPER=9999999
install:
- yes '' | pecl -q install -f mongo

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"mongodb/mongodb": "^1.0.1"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^4.4 || ^5.1",
"squizlabs/php_codesniffer": "^3.2"
},
"provide": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<php>
<!-- Disable deprecation warnings -->
Expand Down
8 changes: 4 additions & 4 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoBinDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class MongoBinDataTest extends TestCase
public function testCreate()
{
$bin = new \MongoBinData(self::GUID, \MongoBinData::FUNC);
$this->assertAttributeSame(self::GUID, 'bin', $bin);
$this->assertAttributeSame(\MongoBinData::FUNC, 'type', $bin);
$this->assertSame(self::GUID, $bin->bin);
$this->assertSame(\MongoBinData::FUNC, $bin->type);

$this->assertSame('<Mongo Binary Data>', (string) $bin);

Expand Down Expand Up @@ -44,7 +44,7 @@ public function testCreateWithBsonBinary()
$bsonBinary = new \MongoDB\BSON\Binary(self::GUID, \MongoDB\BSON\Binary::TYPE_UUID);
$bin = new \MongoBinData($bsonBinary);

$this->assertAttributeSame(self::GUID, 'bin', $bin);
$this->assertAttributeSame(\MongoBinData::UUID_RFC4122, 'type', $bin);
$this->assertSame(self::GUID, $bin->bin);
$this->assertSame(\MongoBinData::UUID_RFC4122, $bin->type);
}
}
2 changes: 1 addition & 1 deletion tests/Alcaeus/MongoDbAdapter/Mongo/MongoClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function provideConnectionUri()

public function testSerialize()
{
$this->assertInternalType('string', serialize($this->getClient()));
$this->assertIsString(serialize($this->getClient()));
}

public function testGetDb()
Expand Down
18 changes: 14 additions & 4 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Alcaeus\MongoDbAdapter\Tests\TestCase;
use Alcaeus\MongoDbAdapter\TypeInterface;
use ReflectionProperty;

/**
* @author alcaeus <[email protected]>
Expand All @@ -13,8 +14,9 @@ class MongoCodeTest extends TestCase
public function testCreate()
{
$code = new \MongoCode('code', ['scope' => 'bleh']);
$this->assertAttributeSame('code', 'code', $code);
$this->assertAttributeSame(['scope' => 'bleh'], 'scope', $code);

$this->assertSame('code', $this->getAttributeValue($code, 'code'));
$this->assertSame(['scope' => 'bleh'], $this->getAttributeValue($code, 'scope'));

$this->assertSame('code', (string) $code);

Expand All @@ -39,7 +41,15 @@ public function testCreateWithBsonObject()
$bsonCode = new \MongoDB\BSON\Javascript('code', ['scope' => 'bleh']);
$code = new \MongoCode($bsonCode);

$this->assertAttributeSame('code', 'code', $code);
$this->assertAttributeSame(['scope' => 'bleh'], 'scope', $code);
$this->assertSame('code', $this->getAttributeValue($code, 'code'));
$this->assertSame(['scope' => 'bleh'], $this->getAttributeValue($code, 'scope'));
}

private function getAttributeValue(\MongoCode $code, $attribute)
{
$property = new ReflectionProperty($code, $attribute);
$property->setAccessible(true);

return $property->getValue($code);
}
}
21 changes: 9 additions & 12 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MongoCollectionTest extends TestCase
{
public function testSerialize()
{
$this->assertInternalType('string', serialize($this->getCollection()));
$this->assertIsString(serialize($this->getCollection()));
}

public function testGetNestedCollections()
Expand Down Expand Up @@ -802,7 +802,7 @@ public function testDistinct()
$this->prepareData();

$values = $this->getCollection()->distinct('foo');
$this->assertInternalType('array', $values);
$this->assertIsArray($values);

sort($values);
$this->assertEquals(['bar', 'foo'], $values);
Expand All @@ -813,7 +813,7 @@ public function testDistinctWithQuery()
$this->prepareData();

$values = $this->getCollection()->distinct('foo', ['foo' => 'bar']);
$this->assertInternalType('array', $values);
$this->assertIsArray($values);
$this->assertEquals(['bar'], $values);
}

Expand Down Expand Up @@ -864,7 +864,7 @@ public function testAggregate()
];

$result = $collection->aggregate($pipeline, ['cursor' => true]);
$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertArrayHasKey('result', $result);

$this->assertEquals([
Expand Down Expand Up @@ -900,7 +900,7 @@ public function testAggregateWithMultiplePilelineOperatorsAsArguments()
$this->fail($msg);
}

$this->assertInternalType('array', $result);
$this->assertIsArray($result);
$this->assertArrayHasKey('result', $result);

$this->assertEquals([
Expand Down Expand Up @@ -1449,17 +1449,14 @@ public function testDeleteIndexes()

public function testDeleteIndexesForNonExistingCollection()
{
$expected = [
'ok' => 0.0,
'errmsg' => 'ns not found',
];
$result = $this->getCollection('nonExisting')->deleteIndexes();

$this->assertSame(0.0, $result['ok']);
$this->assertRegExp('#ns not found#', $result['errmsg']);
if (version_compare($this->getServerVersion(), '3.4.0', '>=')) {
$this->assertSame(26, $result['code']);
$expected['code'] = 26;
}

// Using assertArraySubset because newer versions (3.4.7?) also return `codeName`
$this->assertArraySubset($expected, $this->getCollection('nonExisting')->deleteIndexes());
}

public function dataGetIndexInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testSerialize()
{
$this->prepareData();
$cursor = $this->getCollection()->aggregateCursor([['$match' => ['foo' => 'bar']]]);
$this->assertInternalType('string', serialize($cursor));
$this->assertIsString(serialize($cursor));
}

public function testInfo()
Expand Down
2 changes: 1 addition & 1 deletion tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testSerialize()
{
$this->prepareData();
$cursor = $this->getCollection()->find(['foo' => 'bar']);
$this->assertInternalType('string', serialize($cursor));
$this->assertIsString(serialize($cursor));
}

public function testCursorConvertsTypes()
Expand Down
4 changes: 2 additions & 2 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBRefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testGet()
$db->selectCollection('test')->insert($document);

$fetchedRef = \MongoDBRef::get($db, ['$ref' => 'test', '$id' => $id]);
$this->assertInternalType('array', $fetchedRef);
$this->assertIsArray($fetchedRef);
$this->assertEquals($document, $fetchedRef);
}

Expand All @@ -99,7 +99,7 @@ public function testGetThroughMongoDB()
$db->selectCollection('test')->insert($document);

$fetchedRef = $db->getDBRef(['$ref' => 'test', '$id' => $id]);
$this->assertInternalType('array', $fetchedRef);
$this->assertIsArray($fetchedRef);
$this->assertEquals($document, $fetchedRef);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MongoDBTest extends TestCase
{
public function testSerialize()
{
$this->assertInternalType('string', serialize($this->getDatabase()));
$this->assertIsString(serialize($this->getDatabase()));
}

public function testEmptyDatabaseName()
Expand Down
16 changes: 8 additions & 8 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function testTimeZoneDoesNotAlterReturnedDateTime()
public function testCreate()
{
$date = new \MongoDate(1234567890, 123456);
$this->assertAttributeSame(1234567890, 'sec', $date);
$this->assertAttributeSame(123000, 'usec', $date);
$this->assertSame(1234567890, $date->sec);
$this->assertSame(123000, $date->usec);

$this->assertSame('0.12300000 1234567890', (string) $date);
$dateTime = $date->toDateTime();
Expand Down Expand Up @@ -68,8 +68,8 @@ public function testConvertToBson(\MongoDate $date)
public function testCreateWithString()
{
$date = new \MongoDate('1234567890', '123456');
$this->assertAttributeSame(1234567890, 'sec', $date);
$this->assertAttributeSame(123000, 'usec', $date);
$this->assertSame(1234567890, $date->sec);
$this->assertSame(123000, $date->usec);
}

public function testCreateWithBsonDate()
Expand All @@ -79,15 +79,15 @@ public function testCreateWithBsonDate()
$bsonDate = new \MongoDB\BSON\UTCDateTime(1234567890123);
$date = new \MongoDate($bsonDate);

$this->assertAttributeSame(1234567890, 'sec', $date);
$this->assertAttributeSame(123000, 'usec', $date);
$this->assertSame(1234567890, $date->sec);
$this->assertSame(123000, $date->usec);
}

public function testSupportMillisecondsWithLeadingZeroes()
{
$date = new \MongoDate('1234567890', '012345');
$this->assertAttributeSame(1234567890, 'sec', $date);
$this->assertAttributeSame(12000, 'usec', $date);
$this->assertSame(1234567890, $date->sec);
$this->assertSame(12000, $date->usec);

$this->assertSame('0.01200000 1234567890', (string) $date);
$dateTime = $date->toDateTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MongoDeleteBatchTest extends TestCase
public function testSerialize()
{
$batch = new \MongoDeleteBatch($this->getCollection());
$this->assertInternalType('string', serialize($batch));
$this->assertIsString(serialize($batch));
}

public function testDeleteOne()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testSerialize()
$gridfs->storeBytes('bar', ['filename' => 'bar.txt']);
$cursor = $gridfs->find(['filename' => 'foo.txt']);

$this->assertInternalType('string', serialize($cursor));
$this->assertIsString(serialize($cursor));
}

public function testCursorItems()
Expand Down
2 changes: 1 addition & 1 deletion tests/Alcaeus/MongoDbAdapter/Mongo/MongoGridFSFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testSerialize()
$file = $this->getGridFS()->findOne(['filename' => 'foo']);
$this->assertInstanceOf(\MongoGridFSFile::class, $file);

$this->assertInternalType('string', serialize($file));
$this->assertIsString(serialize($file));
}

public function testFileProperty()
Expand Down
2 changes: 1 addition & 1 deletion tests/Alcaeus/MongoDbAdapter/Mongo/MongoGridFSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MongoGridFSTest extends TestCase
{
public function testSerialize()
{
$this->assertInternalType('string', serialize($this->getGridFS()));
$this->assertIsString(serialize($this->getGridFS()));
}

public function testChunkProperty()
Expand Down
18 changes: 13 additions & 5 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Alcaeus\MongoDbAdapter\Tests\TestCase;
use MongoDB\BSON\ObjectID;
use ReflectionProperty;

/**
* @author alcaeus <[email protected]>
Expand Down Expand Up @@ -40,12 +41,11 @@ public function testCreateWithString()
$this->assertSame(34335, $id->getPID());
}

/**
* @expectedException \MongoException
* @expectedExceptionMessage Invalid object ID
*/
public function testCreateWithInvalidStringThrowsMongoException()
{
$this->expectException('\MongoException');
$this->expectExceptionMessage('Invalid object ID');

new \MongoId('invalid');
}

Expand All @@ -59,7 +59,7 @@ public function testCreateWithObjectId()
$id = new \MongoId($objectId);
$this->assertSame($original, (string) $id);

$this->assertAttributeNotSame($objectId, 'objectID', $id);
$this->assertNotSame($objectId, $this->getAttributeValue($id, 'objectID'));
}

/**
Expand All @@ -83,4 +83,12 @@ public static function dataIsValid()
'object' => [false, new \stdClass()],
];
}

private function getAttributeValue(\MongoId $id, $attribute)
{
$property = new ReflectionProperty($id, $attribute);
$property->setAccessible(true);

return $property->getValue($id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MongoInsertBatchTest extends TestCase
public function testSerialize()
{
$batch = new \MongoInsertBatch($this->getCollection());
$this->assertInternalType('string', serialize($batch));
$this->assertIsString(serialize($batch));
}

public function testInsertBatch()
Expand Down
8 changes: 4 additions & 4 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoRegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class MongoRegexTest extends TestCase
public function testCreate()
{
$regex = new \MongoRegex('/abc/i');
$this->assertAttributeSame('abc', 'regex', $regex);
$this->assertAttributeSame('i', 'flags', $regex);
$this->assertSame('abc', $regex->regex);
$this->assertSame('i', $regex->flags);

$this->assertSame('/abc/i', (string) $regex);

Expand All @@ -41,7 +41,7 @@ public function testCreateWithBsonType()
$bsonRegex = new \MongoDB\BSON\Regex('abc', 'i');
$regex = new \MongoRegex($bsonRegex);

$this->assertAttributeSame('abc', 'regex', $regex);
$this->assertAttributeSame('i', 'flags', $regex);
$this->assertSame('abc', $regex->regex);
$this->assertSame('i', $regex->flags);
}
}
Loading

0 comments on commit 3e1d2b0

Please sign in to comment.