|
25 | 25 | */
|
26 | 26 | class AssociationCollectionTest extends TestCase
|
27 | 27 | {
|
| 28 | + /** |
| 29 | + * @var AssociationCollection |
| 30 | + */ |
| 31 | + public $associations; |
28 | 32 |
|
29 | 33 | /**
|
30 | 34 | * setup
|
@@ -137,39 +141,45 @@ public function testKeys()
|
137 | 141 | $this->assertEquals(['users'], $this->associations->keys());
|
138 | 142 | }
|
139 | 143 |
|
| 144 | + /** |
| 145 | + * Data provider for AssociationCollection::type |
| 146 | + */ |
| 147 | + public function associationCollectionType() |
| 148 | + { |
| 149 | + return [ |
| 150 | + ['BelongsTo','BelongsToMany'], |
| 151 | + ['belongsTo','belongsToMany'], |
| 152 | + ['belongsto','belongstomany'] |
| 153 | + ]; |
| 154 | + } |
| 155 | + |
140 | 156 | /**
|
141 | 157 | * Test getting association names by type.
|
142 | 158 | *
|
143 |
| - * @return void |
| 159 | + * @param string $belongsToStr |
| 160 | + * @param string $belongsToManyStr |
| 161 | + * @dataProvider associationCollectionType |
144 | 162 | */
|
145 |
| - public function testType() |
| 163 | + public function testType($belongsToStr, $belongsToManyStr) |
146 | 164 | {
|
147 |
| - $belongsToCases = ['BelongsTo', 'belongsTo', 'belongsto']; |
148 |
| - $belongsToManyCases = ['BelongsToMany', 'belongsToMany', 'belongstomany']; |
149 |
| - |
150 | 165 | $belongsTo = new BelongsTo('');
|
151 | 166 | $this->associations->add('Users', $belongsTo);
|
152 | 167 |
|
153 | 168 | $belongsToMany = new BelongsToMany('');
|
154 | 169 | $this->associations->add('Tags', $belongsToMany);
|
155 | 170 |
|
156 |
| - foreach ($belongsToCases as $belongsToType) { |
157 |
| - $this->assertSame( |
158 |
| - [$belongsTo], |
159 |
| - $this->associations->type($belongsToType) |
160 |
| - ); |
161 |
| - foreach ($belongsToManyCases as $belongsToManyType) { |
162 |
| - $this->assertSame( |
163 |
| - [$belongsToMany], |
164 |
| - $this->associations->type($belongsToManyType) |
165 |
| - ); |
166 |
| - $this->assertSame( |
167 |
| - [$belongsTo, $belongsToMany], |
168 |
| - $this->associations->type([$belongsToType, $belongsToManyType]) |
169 |
| - ); |
170 |
| - } |
171 |
| - } |
| 171 | + $this->assertSame([$belongsTo], $this->associations->type($belongsToStr)); |
| 172 | + $this->assertSame([$belongsToMany], $this->associations->type($belongsToManyStr)); |
| 173 | + $this->assertSame([$belongsTo, $belongsToMany], $this->associations->type([$belongsToStr, $belongsToManyStr])); |
| 174 | + } |
172 | 175 |
|
| 176 | + /** |
| 177 | + * Type should return empty array. |
| 178 | + * |
| 179 | + * @return void |
| 180 | + */ |
| 181 | + public function hasTypeReturnsEmptyArray() |
| 182 | + { |
173 | 183 | foreach (['HasMany', 'hasMany', 'FooBar', 'DoesNotExist'] as $value) {
|
174 | 184 | $this->assertSame([], $this->associations->type($value));
|
175 | 185 | }
|
|
0 commit comments