This repository was archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPositiveOverNegativeCountTraitTest.php
More file actions
136 lines (118 loc) · 3.55 KB
/
PositiveOverNegativeCountTraitTest.php
File metadata and controls
136 lines (118 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/*
* This file is part of PHPUnit Good Practices.
*
* (c) Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PHPUnitGoodPractices\Tests;
use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\TestCase;
use PHPUnitGoodPractices\PositiveOverNegativeCountTrait;
/**
* @covers \PHPUnitGoodPractices\PositiveOverNegativeCountTrait
*/
final class PositiveOverNegativeCountTraitTest extends TestCase
{
use PositiveOverNegativeCountTrait;
public $fixtureAttributePositive = array(11);
public $fixtureAttributeZero = array();
public function expectException($exception)
{
if (is_callable(array('parent', 'expectException'))) {
parent::expectException($exception);
} else {
$this->setExpectedException($exception);
}
}
/**
* @param array $data
* @param int $expected
* @param bool $shouldCrash
*
* @dataProvider provideAssertCountCases
*/
public function testAssertCount($data, $expected, $shouldCrash)
{
if ($shouldCrash) {
$this->expectException(Warning::class);
}
$this->assertCount($expected, $data);
}
public function provideAssertCountCases()
{
return array(
array(array('foo', 'bar'), 2, false),
array(array(), 0, false),
array(array(), -2, true),
);
}
/**
* @param array $data
* @param int $expected
* @param bool $shouldCrash
*
* @dataProvider provideAssertNotCountCases
*/
public function testAssertNotCount($data, $expected, $shouldCrash)
{
if ($shouldCrash) {
$this->expectException(Warning::class);
}
$this->assertNotCount($expected, $data);
}
public function provideAssertNotCountCases()
{
return array(
array(array('foo', 'bar'), -2, false),
array(array(), 10, false),
array(array(), -2, true),
);
}
/**
* @param string $key
* @param int $expected
* @param bool $shouldCrash
*
* @dataProvider provideAssertAttributeCountCases
*/
public function testAssertAttributeCount($key, $expected, $shouldCrash)
{
if ($shouldCrash) {
$this->expectException(Warning::class);
}
$this->assertAttributeCount($expected, $key, $this);
}
public function provideAssertAttributeCountCases()
{
return array(
array('fixtureAttributePositive', count($this->fixtureAttributePositive), false),
array('fixtureAttributeZero', count($this->fixtureAttributeZero), false),
array('fixtureAttributeZero', -1, true),
);
}
/**
* @param string $key
* @param int $expected
* @param bool $shouldCrash
*
* @dataProvider provideAssertAttributeCountCases
*/
public function testAssertAttributeNotCount($key, $expected, $shouldCrash)
{
if ($shouldCrash) {
$this->expectException(Warning::class);
}
$this->assertAttributeNotCount($expected, $key, $this);
}
public function provideAssertAttributeNotCountCases()
{
return array(
array('fixtureAttributePositive', 10 + count($this->fixtureAttributePositive), false),
array('fixtureAttributeZero', 10 + count($this->fixtureAttributeZero), false),
array('fixtureAttributeZero', -1, true),
);
}
}