Skip to content

Commit 91bf0b2

Browse files
authored
Merge branch 'main' into dependabot/github_actions/shivammathur/setup-php-2.24.0
2 parents 30aae90 + af1f03e commit 91bf0b2

File tree

5 files changed

+137
-75
lines changed

5 files changed

+137
-75
lines changed

.github/workflows/on-pull-request.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ jobs:
1818
- 7.2
1919
- 7.3
2020
- 7.4
21-
# - 8.0
22-
# - 8.1
21+
- 8.0
22+
- 8.1
23+
- 8.2
2324
os:
2425
- ubuntu-latest
25-
# - windows-latest
26-
# - macOS-latest
2726
name: PHP ${{ matrix.php }}; ${{ matrix.os }}
2827
steps:
2928
- name: Setup PHP
@@ -33,26 +32,18 @@ jobs:
3332
extensions: curl, json, mbstring, pcre
3433
ini-values: memory_limit=512M
3534
tools: composer:v2
36-
- name: Check PHP Version
37-
run: php -v
3835
- name: Checkout
39-
uses: actions/checkout@master
36+
uses: actions/checkout@v3
4037
- name: Composer install without dev
4138
run: composer install --no-progress --no-dev --prefer-dist --optimize-autoloader
4239
- name: Composer install with dev
4340
run: composer install --no-progress --prefer-dist --optimize-autoloader
44-
- name: PHPUnit (not windows)
45-
run: ./vendor/bin/phpunit tests/
46-
if: matrix.os != 'windows-latest'
47-
- name: PHPUnit (windows)
48-
run: .\vendor\bin\phpunit tests/
49-
if: matrix.os == 'windows-latest'
41+
- name: PHPUnit
42+
run: composer test
5043

5144
dependabot:
5245
needs: tests
53-
permissions:
54-
pull-requests: write
55-
contents: write
46+
permissions: write-all
5647
runs-on: ubuntu-latest
5748
# Checking the actor will prevent your Action run failing on non-Dependabot
5849
# PRs but also ensures that it only does work for Dependabot PRs.
@@ -62,7 +53,7 @@ jobs:
6253
# will not occur.
6354
- name: Dependabot metadata
6455
id: dependabot-metadata
65-
uses: dependabot/[email protected].5
56+
uses: dependabot/[email protected].6
6657
with:
6758
github-token: "${{ secrets.GITHUB_TOKEN }}"
6859
# Here the PR gets approved.
@@ -78,4 +69,4 @@ jobs:
7869
run: gh pr merge --auto --squash "$PR_URL"
7970
env:
8071
PR_URL: ${{ github.event.pull_request.html_url }}
81-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
/.idea
55
*.bak
66
/vendor/
7-
*.lock
7+
*.lock
8+
/.phpunit.result.cache

composer.json

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
{
2-
"name": "imponeer/object-errors",
3-
"description": "Library that adds a possibility to collect errors for objects",
4-
"keywords": [
5-
"errors",
6-
"collection",
7-
"object"
8-
],
9-
"type": "library",
10-
"require-dev": {
11-
"phpunit/phpunit": "^5.2|^7.0|^8.0",
12-
"mockery/mockery": "^1.0"
13-
},
14-
"require": {
15-
"ext-json": "*",
16-
"php": ">=5.6"
17-
},
18-
"license": "MIT",
19-
"authors": [
20-
{
21-
"name": "Raimondas Rimkevičius",
22-
"email": "[email protected]"
23-
}
24-
],
25-
"autoload": {
26-
"psr-4": {
27-
"Imponeer\\ObjectErrors\\": "src/"
28-
}
2+
"name": "imponeer/object-errors",
3+
"description": "Library that adds a possibility to collect errors for objects",
4+
"keywords": [
5+
"errors",
6+
"collection",
7+
"object"
8+
],
9+
"type": "library",
10+
"require-dev": {
11+
"phpunit/phpunit": "^5.2|^7.0|^8.0",
12+
"mockery/mockery": "^1.0"
13+
},
14+
"require": {
15+
"ext-json": "*",
16+
"php": ">=5.6"
17+
},
18+
"license": "MIT",
19+
"authors": [
20+
{
21+
"name": "Raimondas Rimkevičius",
22+
"email": "[email protected]"
2923
}
24+
],
25+
"autoload": {
26+
"psr-4": {
27+
"Imponeer\\ObjectErrors\\": "src/"
28+
}
29+
},
30+
"scripts": {
31+
"test": "phpunit --testdox"
32+
}
3033
}

tests/ErrorsCollectionTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,20 @@ public function testStringConversion() {
134134

135135
$this->assertNotEmpty((string) $instance, 'Converted to string not empty ErrorsCollection must be not empty');
136136
$this->assertNotEmpty($instance->getHtml(), 'Converted to HTML not empty ErrorsCollection must be not empty');
137-
$this->assertInternalType('string', $instance->getHtml(), 'getHTML must generate strings');
137+
138+
if (method_exists($this, 'assertIsString')) {
139+
$this->assertIsString($instance->getHtml(), 'getHTML must generate strings');
140+
} else {
141+
$this->assertInternalType('string', $instance->getHtml(), 'getHTML must generate strings');
142+
}
138143
}
139144

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

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

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

178-
$this->assertInternalType('array', $instance->toArray(), 'toArray doesn\'t makes an array');
179-
$this->assertInternalType('string', $instance->toJson(), 'toJSON doesn\'t makes a string');
183+
if (method_exists($this, 'assertIsString')) {
184+
$this->assertIsArray($instance->toArray(), 'toArray doesn\'t makes an array');
185+
$this->assertIsString($instance->toJson(), 'toJSON doesn\'t makes a string');
186+
} else {
187+
$this->assertInternalType('array', $instance->toArray(), 'toArray doesn\'t makes an array');
188+
$this->assertInternalType('string', $instance->toJson(), 'toJSON doesn\'t makes a string');
189+
}
180190
}
181191

182192
}

tests/ErrorsTraitTest.php

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,97 @@
88
class ErrorsTraitTest extends TestCase
99
{
1010

11+
/**
12+
* Creates mock for ErrorsTrait
13+
*
14+
* @return Mockery\Mock|ErrorsTrait
15+
*
16+
* @noinspection PhpReturnDocTypeMismatchInspection
17+
*/
18+
protected function createTraitMock() {
19+
$mock = Mockery::mock(ErrorsTrait::class)->makePartial();
20+
$mock->__construct();
21+
22+
return $mock;
23+
}
24+
1125
public function testGetErrors()
1226
{
13-
$mock = Mockery::mock(ErrorsTrait::class)->makePartial();
14-
$mock->shouldReceive('getErrors')->withArgs([false])->once()->andReturnUsing(
15-
function ($ret) {
16-
$this->assertInternalType('array', $ret, 'getErrors without param must return array');
17-
}
18-
);
19-
$mock->shouldReceive('getErrors')->withArgs([true])->once()->andReturnUsing(
20-
function ($ret) {
21-
$this->assertInternalType('string', $ret, 'getErrors without param must return string');
22-
}
23-
);
27+
$mock = $this->createTraitMock();
28+
29+
if (method_exists($this, 'assertIsString')) {
30+
31+
$this->assertIsArray(
32+
$mock->getErrors(false),
33+
'getErrors without param must return array'
34+
);
35+
36+
$this->assertIsString(
37+
$mock->getErrors(true),
38+
'getErrors without param must return string'
39+
);
40+
41+
} else {
42+
43+
$this->assertInternalType(
44+
'array',
45+
$mock->getErrors(false),
46+
'getErrors without param must return array'
47+
);
48+
49+
$this->assertInternalType(
50+
'string',
51+
$mock->getErrors(true),
52+
'getErrors without param must return string'
53+
);
54+
55+
}
2456
}
2557

2658
public function testGetHtmlErrors()
2759
{
28-
$mock = Mockery::mock(ErrorsTrait::class)->makePartial();
29-
$mock->shouldReceive('getHtmlErrors')->once()->andReturnUsing(
30-
function ($ret) {
31-
$this->assertInternalType('string', $ret, 'getErrors without param must return array');
32-
}
33-
);
60+
$mock = $this->createTraitMock();
61+
62+
if (method_exists($this, 'assertIsString')) {
63+
$this->assertIsString(
64+
$mock->getHtmlErrors(),
65+
'getErrors without param must return array'
66+
);
67+
} else {
68+
$this->assertInternalType(
69+
'string',
70+
$mock->getHtmlErrors(),
71+
'getErrors without param must return array'
72+
);
73+
}
3474
}
3575

3676
public function testHasAndSetError()
3777
{
38-
$mock = Mockery::mock(ErrorsTrait::class)->makePartial();
39-
$mock->shouldReceive('hasError')->once()->andReturn(0);
40-
$mock->shouldReceive('setErrors')
41-
->withArgs([md5(time())])
42-
->getMock()
43-
->shouldReceive('hasError')
44-
->andReturn(1);
78+
$mock = $this->createTraitMock();
79+
80+
if (method_exists($this, 'assertIsBool')) {
81+
$this->assertIsBool(
82+
$mock->hasError(),
83+
'hasError method should return bool'
84+
);
85+
} else {
86+
$this->assertInternalType(
87+
'bool',
88+
$mock->hasError(),
89+
'hasError method should return bool'
90+
);
91+
}
92+
$this->assertFalse(
93+
$mock->hasError(),
94+
'When there are no errors hasError should return false'
95+
);
96+
97+
$mock->setErrors("some errors");
98+
$this->assertTrue(
99+
$mock->hasError(),
100+
'When there are some errors hasError should return true'
101+
);
45102
}
46103

47104
}

0 commit comments

Comments
 (0)