-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MarioBlazek/master
Implemented PHPUnit tests
- Loading branch information
Showing
8 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
language: php | ||
|
||
cache: | ||
directories: | ||
- vendor | ||
|
||
matrix: | ||
# mark as finished before allow_failures are run | ||
fast_finish: true | ||
include: | ||
- php: 5.5 | ||
- php: 5.6 | ||
- php: 7.0 | ||
|
||
# test only master (+ pull requests) | ||
branches: | ||
only: | ||
- master | ||
|
||
# make sure to update composer to latest available version | ||
before_install: | ||
- phpenv config-add travis.php.ini | ||
- phpenv config-rm xdebug.ini | ||
|
||
# install dependencies | ||
install: composer install | ||
|
||
# execute phpunit as the script command | ||
script: | ||
- ./vendor/bin/phpunit -d memory_limit=-1 --colors -c phpunit.xml | ||
|
||
# disable mail notifications | ||
notification: | ||
email: false | ||
|
||
# reduce depth (history) of git checkout | ||
git: | ||
depth: 30 | ||
|
||
# we don't need sudo | ||
sudo: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
namespace Netgen\Bundle\ContentTypeListBundle\Tests\Core\FieldType\ContentTypeList; | ||
|
||
use eZ\Publish\Core\FieldType\FieldType; | ||
use Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Type; | ||
use Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Value; | ||
|
||
class TypeTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Type | ||
*/ | ||
protected $type; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $identifiers = array('identifier0', 'identifier1'); | ||
|
||
/** | ||
* @var Value | ||
*/ | ||
protected $value; | ||
|
||
/** | ||
* @var Value | ||
*/ | ||
protected $emptyValue; | ||
|
||
public function setUp() | ||
{ | ||
$this->type = new Type(); | ||
$this->value = new Value($this->identifiers); | ||
$this->emptyValue = new Value(); | ||
} | ||
|
||
public function testInstanceOfFieldType() | ||
{ | ||
$this->assertInstanceOf(FieldType::class, $this->type); | ||
} | ||
|
||
public function testToHash() | ||
{ | ||
$this->assertEquals($this->identifiers, $this->type->toHash($this->value)); | ||
} | ||
|
||
public function testGetFieldTypeIdentifier() | ||
{ | ||
$this->assertEquals('ngclasslist', $this->type->getFieldTypeIdentifier()); | ||
} | ||
|
||
public function testGetEmptyValue() | ||
{ | ||
$this->assertEquals($this->emptyValue, $this->type->getEmptyValue()); | ||
} | ||
|
||
public function testGetName() | ||
{ | ||
$this->assertEquals(implode(', ', $this->identifiers), $this->type->getName($this->value)); | ||
} | ||
|
||
public function testIsEmptyValue() | ||
{ | ||
$this->assertFalse($this->type->isEmptyValue($this->value)); | ||
$this->assertTrue($this->type->isEmptyValue($this->emptyValue)); | ||
} | ||
|
||
public function testFromHashWithStringArgument() | ||
{ | ||
$this->assertEquals($this->emptyValue, $this->type->fromHash('test')); | ||
} | ||
|
||
public function testFromHashWithArrayOfNumbers() | ||
{ | ||
$this->assertEquals($this->emptyValue, $this->type->fromHash(array(123, 456))); | ||
} | ||
|
||
public function testFromHash() | ||
{ | ||
$this->assertEquals($this->value, $this->type->fromHash($this->identifiers)); | ||
} | ||
|
||
public function testAcceptValueWithArrayOfStringIdentifiers() | ||
{ | ||
$this->type->acceptValue($this->identifiers); | ||
} | ||
|
||
/** | ||
* @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType | ||
* @expectedExceptionMessage Argument '$value' is invalid: expected value to be of type 'Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Value', got 'array' | ||
*/ | ||
public function testAcceptValueWithArrayOfNumbers() | ||
{ | ||
$this->type->acceptValue(array(123, 456)); | ||
} | ||
|
||
/** | ||
* @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType | ||
* @expectedExceptionMessage Argument '$value->identifiers' is invalid: expected value to be of type 'array', got 'string' | ||
*/ | ||
public function testAcceptValueWithValueIdentifiersAsString() | ||
{ | ||
$this->value->identifiers = 'test'; | ||
|
||
$this->type->acceptValue($this->value); | ||
} | ||
|
||
/** | ||
* @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType | ||
* @expectedExceptionMessage Argument '123' is invalid: expected value to be of type 'Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Value', got 'integer' | ||
*/ | ||
public function testAcceptValueWithValueIdentifiersAsArrayOfNumbers() | ||
{ | ||
$this->value->identifiers = array(123, 456); | ||
|
||
$this->type->acceptValue($this->value); | ||
} | ||
|
||
public function testToPersistenceValue() | ||
{ | ||
$this->type->toPersistenceValue($this->value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Netgen\Bundle\ContentTypeListBundle\Tests\Core\FieldType\ContentTypeList; | ||
|
||
use eZ\Publish\Core\FieldType\Value as BaseValue; | ||
use Netgen\Bundle\ContentTypeListBundle\Core\FieldType\ContentTypeList\Value; | ||
|
||
class ValueTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Value | ||
*/ | ||
protected $value; | ||
|
||
public function setUp() | ||
{ | ||
$this->value = new Value( | ||
array( | ||
'identifier0', 'identifier1', | ||
) | ||
); | ||
} | ||
|
||
public function testInstanceOfFieldTypeValue() | ||
{ | ||
$this->assertInstanceOf(BaseValue::class, $this->value); | ||
} | ||
|
||
public function testToStringMethod() | ||
{ | ||
$identifiers = 'identifier0, identifier1'; | ||
|
||
$this->assertEquals($identifiers, strval($this->value)); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
Tests/Core/Persistence/Legacy/Content/FieldValue/Converter/ContentTypeListConverterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Netgen\Bundle\ContentTypeListBundle\Tests\Core\Persistence\Legacy\Content\FieldValue\Converter; | ||
|
||
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition; | ||
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue; | ||
use eZ\Publish\SPI\Persistence\Content\FieldValue; | ||
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition; | ||
use Netgen\Bundle\ContentTypeListBundle\Core\Persistence\Legacy\Content\FieldValue\Converter\ContentTypeListConverter; | ||
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter; | ||
|
||
class ContentTypeListConverterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ContentTypeListConverter | ||
*/ | ||
protected $converter; | ||
|
||
public function setUp() | ||
{ | ||
$this->converter = new ContentTypeListConverter(); | ||
} | ||
|
||
public function testInstanceOfConverterInterface() | ||
{ | ||
$this->assertInstanceOf(Converter::class, $this->converter); | ||
} | ||
|
||
public function testCreate() | ||
{ | ||
$this->assertEquals($this->converter, ContentTypeListConverter::create()); | ||
} | ||
|
||
public function testToStorageFieldDefinition() | ||
{ | ||
$fieldDefinition = new FieldDefinition(); | ||
$storageDefinition = new StorageFieldDefinition(); | ||
|
||
$this->converter->toStorageFieldDefinition($fieldDefinition, $storageDefinition); | ||
} | ||
|
||
public function testToFieldDefinition() | ||
{ | ||
$fieldDefinition = new FieldDefinition(); | ||
$storageDefinition = new StorageFieldDefinition(); | ||
|
||
$this->converter->toFieldDefinition($storageDefinition, $fieldDefinition); | ||
} | ||
|
||
public function testGetIndexColumn() | ||
{ | ||
$this->assertFalse($this->converter->getIndexColumn()); | ||
} | ||
|
||
public function testToFieldValue() | ||
{ | ||
$fieldDefinition = new FieldValue(); | ||
$storageDefinition = new StorageFieldValue(); | ||
|
||
$this->converter->toFieldValue($storageDefinition, $fieldDefinition); | ||
} | ||
|
||
public function testToStorageValue() | ||
{ | ||
$fieldDefinition = new FieldValue(); | ||
$storageDefinition = new StorageFieldValue(); | ||
|
||
$this->converter->toStorageValue($fieldDefinition, $storageDefinition); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Netgen\ContentTypeList\Tests"> | ||
<directory>Tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory>.</directory> | ||
<exclude> | ||
<directory>DependencyInjection</directory> | ||
<directory>Resources</directory> | ||
<directory>Tests</directory> | ||
<directory>vendor</directory> | ||
<file>NetgenContentTypeListBundle.php</file> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[PHP] | ||
|
||
memory_limit = 2G |