Skip to content

CI tests with PHP 8.2 and some tests fixes #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ jobs:
- 7.2
- 7.3
- 7.4
# - 8.0
# - 8.1
- 8.0
- 8.1
- 8.2
os:
- ubuntu-latest
# - windows-latest
# - macOS-latest
name: PHP ${{ matrix.php }}; ${{ matrix.os }}
steps:
- name: Setup PHP
Expand All @@ -33,20 +32,14 @@ jobs:
extensions: curl, json, mbstring, pcre
ini-values: memory_limit=512M
tools: composer:v2
- name: Check PHP Version
run: php -v
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v3
- name: Composer install without dev
run: composer install --no-progress --no-dev --prefer-dist --optimize-autoloader
- name: Composer install with dev
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: PHPUnit (not windows)
run: ./vendor/bin/phpunit tests/
if: matrix.os != 'windows-latest'
- name: PHPUnit (windows)
run: .\vendor\bin\phpunit tests/
if: matrix.os == 'windows-latest'
- name: PHPUnit
run: composer test

dependabot:
needs: tests
Expand Down Expand Up @@ -78,4 +71,4 @@ jobs:
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.idea
*.bak
/vendor/
*.lock
*.lock
/.phpunit.result.cache
57 changes: 30 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
{
"name": "imponeer/object-errors",
"description": "Library that adds a possibility to collect errors for objects",
"keywords": [
"errors",
"collection",
"object"
],
"type": "library",
"require-dev": {
"phpunit/phpunit": "^5.2|^7.0|^8.0",
"mockery/mockery": "^1.0"
},
"require": {
"ext-json": "*",
"php": ">=5.6"
},
"license": "MIT",
"authors": [
{
"name": "Raimondas Rimkevičius",
"email": "mekdrop@impresscms.org"
}
],
"autoload": {
"psr-4": {
"Imponeer\\ObjectErrors\\": "src/"
}
"name": "imponeer/object-errors",
"description": "Library that adds a possibility to collect errors for objects",
"keywords": [
"errors",
"collection",
"object"
],
"type": "library",
"require-dev": {
"phpunit/phpunit": "^5.2|^7.0|^8.0",
"mockery/mockery": "^1.0"
},
"require": {
"ext-json": "*",
"php": ">=5.6"
},
"license": "MIT",
"authors": [
{
"name": "Raimondas Rimkevičius",
"email": "mekdrop@impresscms.org"
}
],
"autoload": {
"psr-4": {
"Imponeer\\ObjectErrors\\": "src/"
}
},
"scripts": {
"test": "phpunit --testdox"
}
}
20 changes: 15 additions & 5 deletions tests/ErrorsCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,20 @@ public function testStringConversion() {

$this->assertNotEmpty((string) $instance, 'Converted to string not empty ErrorsCollection must be not empty');
$this->assertNotEmpty($instance->getHtml(), 'Converted to HTML not empty ErrorsCollection must be not empty');
$this->assertInternalType('string', $instance->getHtml(), 'getHTML must generate strings');

if (method_exists($this, 'assertIsString')) {
$this->assertIsString($instance->getHtml(), 'getHTML must generate strings');
} else {
$this->assertInternalType('string', $instance->getHtml(), 'getHTML must generate strings');
}
}

public function testCount() {
$instance = new ErrorsCollection();
$this->assertSame($instance->count(), 0, 'Count is not 0 when collection was just created');
$this->assertSame(0, $instance->count(), 'Count is not 0 when collection was just created');

$instance->add(crc32(time()));
$this->assertSame($instance->count(), 1, 'Count must be 1 after one element was added');
$this->assertSame(1, $instance->count(), 'Count must be 1 after one element was added');

$this->assertCount(1, $instance, 'Count function doesn\'t work');
}
Expand Down Expand Up @@ -175,8 +180,13 @@ public function testSerialization() {
$this->assertSame($instance->mode, $unserialized->mode, 'Serialization-unserialization fails #1');
$this->assertSame($instance->toArray(), $unserialized->toArray(), 'Serialization-unserialization fails #2');

$this->assertInternalType('array', $instance->toArray(), 'toArray doesn\'t makes an array');
$this->assertInternalType('string', $instance->toJson(), 'toJSON doesn\'t makes a string');
if (method_exists($this, 'assertIsString')) {
$this->assertIsArray($instance->toArray(), 'toArray doesn\'t makes an array');
$this->assertIsString($instance->toJson(), 'toJSON doesn\'t makes a string');
} else {
$this->assertInternalType('array', $instance->toArray(), 'toArray doesn\'t makes an array');
$this->assertInternalType('string', $instance->toJson(), 'toJSON doesn\'t makes a string');
}
}

}
105 changes: 81 additions & 24 deletions tests/ErrorsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,97 @@
class ErrorsTraitTest extends TestCase
{

/**
* Creates mock for ErrorsTrait
*
* @return Mockery\Mock|ErrorsTrait
*
* @noinspection PhpReturnDocTypeMismatchInspection
*/
protected function createTraitMock() {
$mock = Mockery::mock(ErrorsTrait::class)->makePartial();
$mock->__construct();

return $mock;
}

public function testGetErrors()
{
$mock = Mockery::mock(ErrorsTrait::class)->makePartial();
$mock->shouldReceive('getErrors')->withArgs([false])->once()->andReturnUsing(
function ($ret) {
$this->assertInternalType('array', $ret, 'getErrors without param must return array');
}
);
$mock->shouldReceive('getErrors')->withArgs([true])->once()->andReturnUsing(
function ($ret) {
$this->assertInternalType('string', $ret, 'getErrors without param must return string');
}
);
$mock = $this->createTraitMock();

if (method_exists($this, 'assertIsString')) {

$this->assertIsArray(
$mock->getErrors(false),
'getErrors without param must return array'
);

$this->assertIsString(
$mock->getErrors(true),
'getErrors without param must return string'
);

} else {

$this->assertInternalType(
'array',
$mock->getErrors(false),
'getErrors without param must return array'
);

$this->assertInternalType(
'string',
$mock->getErrors(true),
'getErrors without param must return string'
);

}
}

public function testGetHtmlErrors()
{
$mock = Mockery::mock(ErrorsTrait::class)->makePartial();
$mock->shouldReceive('getHtmlErrors')->once()->andReturnUsing(
function ($ret) {
$this->assertInternalType('string', $ret, 'getErrors without param must return array');
}
);
$mock = $this->createTraitMock();

if (method_exists($this, 'assertIsString')) {
$this->assertIsString(
$mock->getHtmlErrors(),
'getErrors without param must return array'
);
} else {
$this->assertInternalType(
'string',
$mock->getHtmlErrors(),
'getErrors without param must return array'
);
}
}

public function testHasAndSetError()
{
$mock = Mockery::mock(ErrorsTrait::class)->makePartial();
$mock->shouldReceive('hasError')->once()->andReturn(0);
$mock->shouldReceive('setErrors')
->withArgs([md5(time())])
->getMock()
->shouldReceive('hasError')
->andReturn(1);
$mock = $this->createTraitMock();

if (method_exists($this, 'assertIsBool')) {
$this->assertIsBool(
$mock->hasError(),
'hasError method should return bool'
);
} else {
$this->assertInternalType(
'bool',
$mock->hasError(),
'hasError method should return bool'
);
}
$this->assertFalse(
$mock->hasError(),
'When there are no errors hasError should return false'
);

$mock->setErrors("some errors");
$this->assertTrue(
$mock->hasError(),
'When there are some errors hasError should return true'
);
}

}