Skip to content

Commit 1f58d53

Browse files
committed
Upgrade to PHPUnit 8/9
1 parent 23bbc42 commit 1f58d53

File tree

8 files changed

+69
-82
lines changed

8 files changed

+69
-82
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"doctrine/persistence": "^1.3.4",
3838
"friendsofphp/php-cs-fixer": "^2.7",
3939
"mongodb/mongodb": "^1.2",
40-
"phpunit/phpunit": "^7.5",
40+
"phpunit/phpunit": "^8.5|^9.0",
4141
"ruflin/elastica": "^6.0|^7.0",
4242
"symfony/browser-kit": "^4.1|^5.0",
4343
"symfony/css-selector": "^4.1|^5.0",

tests/Functional/FunctionalTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function testFrontend()
4141
$this->assertSuccessful($response = $this->client->getResponse());
4242

4343
$content = $response->getContent();
44-
$this->assertContains('"name":"dt"', $content);
45-
$this->assertContains('(filtered from _MAX_ total entries)', $content);
44+
$this->assertStringContainsString('"name":"dt"', $content);
45+
$this->assertStringContainsString('(filtered from _MAX_ total entries)', $content);
4646
$json = $this->callDataTableUrl('/?_dt=noCDN&_init=true');
4747
$this->assertEmpty($json->data);
4848
}
@@ -56,7 +56,7 @@ public function testPlainDataTable()
5656
$this->assertSame(125, $json->recordsFiltered);
5757
$this->assertCount(50, $json->data);
5858

59-
$this->assertContains('<table id="persons"', $json->template);
59+
$this->assertStringContainsString('<table id="persons"', $json->template);
6060
$this->assertNotEmpty($json->options);
6161

6262
$sample = $json->data[5];
@@ -133,9 +133,9 @@ public function testTranslation(string $locale, string $languageProcessing, stri
133133
$this->assertSuccessful($response = $this->client->getResponse());
134134

135135
$content = $response->getContent();
136-
$this->assertNotContains('"options":{"language":{"url"', $content);
137-
$this->assertContains(sprintf('"processing":"%s"', $languageProcessing), $content);
138-
$this->assertContains(sprintf('"infoFiltered":"%s"', $languageInfoFiltered), $content);
136+
$this->assertStringNotContainsString('"options":{"language":{"url"', $content);
137+
$this->assertStringContainsString(sprintf('"processing":"%s"', $languageProcessing), $content);
138+
$this->assertStringContainsString(sprintf('"infoFiltered":"%s"', $languageInfoFiltered), $content);
139139
}
140140

141141
public function translationProvider(): array
@@ -152,7 +152,7 @@ private function callDataTableUrl(string $url)
152152
$this->client->enableProfiler();
153153
$this->client->request('GET', $url);
154154
$this->assertSuccessful($response = $this->client->getResponse());
155-
$this->assertContains('application/json', $response->headers->get('Content-type'));
155+
$this->assertStringContainsString('application/json', $response->headers->get('Content-type'));
156156

157157
return json_decode($response->getContent());
158158
}

tests/Unit/Adapter/DoctrineTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
2121
use Omines\DataTablesBundle\Column\TextColumn;
2222
use Omines\DataTablesBundle\DataTable;
23+
use Omines\DataTablesBundle\Exception\InvalidConfigurationException;
2324
use PHPUnit\Framework\TestCase;
2425
use Symfony\Component\EventDispatcher\EventDispatcher;
2526
use Symfony\Component\HttpFoundation\Request;
@@ -58,34 +59,29 @@ public function testSearchCriteriaProvider()
5859
$this->assertTrue(true);
5960
}
6061

61-
/**
62-
* @expectedException \LogicException
63-
* @expectedExceptionMessage doctrine/doctrine-bundle
64-
*/
6562
public function testORMAdapterRequiresDependency()
6663
{
64+
$this->expectException(\LogicException::class);
65+
$this->expectExceptionMessage('doctrine/doctrine-bundle');
6766
(new ORMAdapter());
6867
}
6968

70-
/**
71-
* @expectedException \Omines\DataTablesBundle\Exception\InvalidConfigurationException
72-
* @expectedExceptionMessage Provider must be a callable or implement QueryBuilderProcessorInterface
73-
*/
7469
public function testInvalidQueryProcessorThrows()
7570
{
71+
$this->expectException(InvalidConfigurationException::class);
72+
$this->expectExceptionMessage('Provider must be a callable or implement QueryBuilderProcessorInterface');
7673
(new ORMAdapter($this->createMock(ManagerRegistry::class)))
7774
->configure([
7875
'entity' => 'bar',
7976
'query' => ['foo'],
8077
]);
8178
}
8279

83-
/**
84-
* @expectedException \Omines\DataTablesBundle\Exception\InvalidConfigurationException
85-
* @expectedExceptionMessage Field name 'invalid' must consist at least of an alias and a field
86-
*/
8780
public function testInvalidFieldThrows()
8881
{
82+
$this->expectException(InvalidConfigurationException::class);
83+
$this->expectExceptionMessage("Field name 'invalid' must consist at least of an alias and a field");
84+
8985
$query = $this->createMock(AdapterQuery::class);
9086
$query->method('get')->willReturn([]);
9187
$column = new TextColumn();

tests/Unit/Adapter/ORMAdapterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Tests\Unit\Adapter;
1414

15+
use Doctrine\ORM\Query\QueryException;
1516
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
1617
use Omines\DataTablesBundle\DataTableFactory;
1718
use Omines\DataTablesBundle\DataTableState;
@@ -29,12 +30,11 @@ protected function setUp(): void
2930
$this->factory = $kernel->getContainer()->get(DataTableFactory::class);
3031
}
3132

32-
/**
33-
* @expectedException \Doctrine\ORM\Query\QueryException
34-
* @expectedExceptionMessage Iterate with fetch join in class Tests\Fixtures\AppBundle\Entity\Employee using association company not allowed.
35-
*/
3633
public function testCountGroupedDataTable()
3734
{
35+
$this->expectException(QueryException::class);
36+
$this->expectExceptionMessage('Iterate with fetch join in class Tests\Fixtures\AppBundle\Entity\Employee using association company not allowed.');
37+
3838
$datatable = $this->factory->createFromType(GroupedTableType::class);
3939
/** @var ORMAdapter $adapter */
4040
$adapter = $datatable->getAdapter();

tests/Unit/AdapterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Doctrine\Bundle\DoctrineBundle\Registry;
1616
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
17+
use Omines\DataTablesBundle\Exception\InvalidConfigurationException;
1718
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
1819

1920
/**
@@ -23,12 +24,11 @@
2324
*/
2425
class AdapterTest extends KernelTestCase
2526
{
26-
/**
27-
* @expectedException \Omines\DataTablesBundle\Exception\InvalidConfigurationException
28-
* @expectedExceptionMessage Doctrine has no manager for entity "foobar"
29-
*/
3027
public function testInvalidEntity()
3128
{
29+
$this->expectException(InvalidConfigurationException::class);
30+
$this->expectExceptionMessage('Doctrine has no manager for entity "foobar"');
31+
3232
/** @var Registry $registryMock */
3333
$registryMock = $this->createMock(Registry::class);
3434
$adapter = new ORMAdapter($registryMock);

tests/Unit/ColumnTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Omines\DataTablesBundle\Column\TextColumn;
2020
use Omines\DataTablesBundle\Column\TwigColumn;
2121
use Omines\DataTablesBundle\DataTable;
22+
use Omines\DataTablesBundle\Exception\MissingDependencyException;
2223
use PHPUnit\Framework\TestCase;
2324
use Symfony\Component\EventDispatcher\EventDispatcher;
2425

@@ -132,12 +133,11 @@ public function testColumnWithClosures()
132133
$this->assertSame('BAR', $column->transform(null));
133134
}
134135

135-
/**
136-
* @expectedException \Omines\DataTablesBundle\Exception\MissingDependencyException
137-
* @expectedExceptionMessage You must have TwigBundle installed to use
138-
*/
139136
public function testTwigDependencyDetection()
140137
{
138+
$this->expectException(MissingDependencyException::class);
139+
$this->expectExceptionMessage('You must have TwigBundle installed to use');
140+
141141
new TwigColumn();
142142
}
143143
}

tests/Unit/DataTableTest.php

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
use Omines\DataTablesBundle\DataTablesBundle;
2121
use Omines\DataTablesBundle\DependencyInjection\DataTablesExtension;
2222
use Omines\DataTablesBundle\DependencyInjection\Instantiator;
23+
use Omines\DataTablesBundle\Exception\InvalidArgumentException;
24+
use Omines\DataTablesBundle\Exception\InvalidConfigurationException;
25+
use Omines\DataTablesBundle\Exception\InvalidStateException;
2326
use Omines\DataTablesBundle\Twig\TwigRenderer;
2427
use PHPUnit\Framework\TestCase;
2528
use Symfony\Component\DependencyInjection\ContainerBuilder;
2629
use Symfony\Component\DependencyInjection\ServiceLocator;
2730
use Symfony\Component\EventDispatcher\EventDispatcher;
2831
use Symfony\Component\HttpFoundation\Request;
32+
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
2933
use Tests\Fixtures\AppBundle\DataTable\Type\RegularPersonTableType;
3034

3135
/**
@@ -103,12 +107,11 @@ public function testPostMethod()
103107
$this->assertSame(684, $datatable->getState()->getDraw());
104108
}
105109

106-
/**
107-
* @expectedException \LogicException
108-
* @expectedExceptionMessage Could not resolve type
109-
*/
110110
public function testFactoryFailsOnInvalidType()
111111
{
112+
$this->expectException(\LogicException::class);
113+
$this->expectExceptionMessage('Could not resolve type');
114+
112115
$dummy = new ServiceLocator([]);
113116
$container = new ContainerBuilder();
114117
(new DataTablesExtension())->load([], $container);
@@ -117,66 +120,58 @@ public function testFactoryFailsOnInvalidType()
117120
$factory->createFromType('foobar');
118121
}
119122

120-
/**
121-
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
122-
*/
123123
public function testInvalidOption()
124124
{
125+
$this->expectException(UndefinedOptionsException::class);
126+
125127
$this->createMockDataTable(['option' => 'bar']);
126128
}
127129

128-
/**
129-
* @expectedException \InvalidArgumentException
130-
*/
131130
public function testDataTableInvalidColumn()
132131
{
132+
$this->expectException(\InvalidArgumentException::class);
133+
133134
$this->createMockDataTable()->getColumn(5);
134135
}
135136

136-
/**
137-
* @expectedException \InvalidArgumentException
138-
*/
139137
public function testDataTableInvalidColumnByName()
140138
{
139+
$this->expectException(\InvalidArgumentException::class);
140+
141141
$this->createMockDataTable()->getColumnByName('foo');
142142
}
143143

144-
/**
145-
* @expectedException \InvalidArgumentException
146-
* @expectedExceptionMessage There already is a column with name
147-
*/
148144
public function testDuplicateColumnNameThrows()
149145
{
146+
$this->expectException(\InvalidArgumentException::class);
147+
$this->expectExceptionMessage('There already is a column with name');
148+
150149
$this->createMockDataTable()
151150
->add('foo', TextColumn::class)
152151
->add('foo', TextColumn::class)
153152
;
154153
}
155154

156-
/**
157-
* @expectedException \InvalidArgumentException
158-
* @expectedExceptionMessage Could not resolve type "foo\bar" to a service or class, are you missing a use statement? Or is it implemented but does it not correctly derive from "Omines\DataTablesBundle\Adapter\AdapterInterface"?
159-
*/
160155
public function testInvalidAdapterThrows()
161156
{
157+
$this->expectException(\InvalidArgumentException::class);
158+
$this->expectExceptionMessage('Could not resolve type "foo\\bar" to a service or class, are you missing a use statement? Or is it implemented but does it not correctly derive from "Omines\\DataTablesBundle\\Adapter\\AdapterInterface"?');
159+
162160
$this->createMockDataTable()->createAdapter('foo\bar');
163161
}
164162

165-
/**
166-
* @expectedException \InvalidArgumentException
167-
* @expectedExceptionMessage Could not resolve type "bar" to a service or class, are you missing a use statement? Or is it implemented but does it not correctly derive from "Omines\DataTablesBundle\Column\AbstractColumn"?
168-
*/
169163
public function testInvalidColumnThrows()
170164
{
165+
$this->expectException(\InvalidArgumentException::class);
166+
$this->expectExceptionMessage('Could not resolve type "bar" to a service or class, are you missing a use statement? Or is it implemented but does it not correctly derive from "Omines\\DataTablesBundle\\Column\\AbstractColumn"?');
167+
171168
$this->createMockDataTable()->add('foo', 'bar');
172169
}
173170

174-
/**
175-
* @expectedException \Omines\DataTablesBundle\Exception\InvalidStateException
176-
* @expectedExceptionMessage No adapter was configured yet to retrieve data with
177-
*/
178171
public function testMissingAdapterThrows()
179172
{
173+
$this->expectException(InvalidStateException::class);
174+
$this->expectExceptionMessage('No adapter was configured yet to retrieve data with');
180175
$datatable = $this->createMockDataTable();
181176
$datatable
182177
->setMethod(Request::METHOD_GET)
@@ -185,41 +180,37 @@ public function testMissingAdapterThrows()
185180
;
186181
}
187182

188-
/**
189-
* @expectedException \Omines\DataTablesBundle\Exception\InvalidArgumentException
190-
* @expectedExceptionMessage DataTable name cannot be empty
191-
*/
192183
public function testEmptyNameThrows()
193184
{
185+
$this->expectException(InvalidArgumentException::class);
186+
$this->expectExceptionMessage('DataTable name cannot be empty');
187+
194188
$this->createMockDataTable()->setName('');
195189
}
196190

197-
/**
198-
* @expectedException \Omines\DataTablesBundle\Exception\InvalidConfigurationException
199-
* @expectedExceptionMessage Unknown request method 'OPTIONS'
200-
*/
201191
public function testStateWillNotProcessInvalidMethod()
202192
{
193+
$this->expectException(InvalidConfigurationException::class);
194+
$this->expectExceptionMessage("Unknown request method 'OPTIONS'");
195+
203196
$datatable = $this->createMockDataTable();
204197
$datatable->setMethod(Request::METHOD_OPTIONS);
205198
$datatable->handleRequest(Request::create('/foo'));
206199
}
207200

208-
/**
209-
* @expectedException \Omines\DataTablesBundle\Exception\InvalidStateException
210-
* @expectedExceptionMessage The DataTable does not know its state yet
211-
*/
212201
public function testMissingStateThrows()
213202
{
203+
$this->expectException(InvalidStateException::class);
204+
$this->expectExceptionMessage('The DataTable does not know its state yet');
205+
214206
$this->createMockDataTable()->getResponse();
215207
}
216208

217-
/**
218-
* @expectedException \Omines\DataTablesBundle\Exception\InvalidArgumentException
219-
* @expectedExceptionMessage Could not resolve type "foo" to a service or class
220-
*/
221209
public function testInvalidDataTableTypeThrows()
222210
{
211+
$this->expectException(InvalidArgumentException::class);
212+
$this->expectExceptionMessage('Could not resolve type "foo" to a service or class');
213+
223214
(new DataTableFactory([], $this->createMock(DataTableRendererInterface::class), new Instantiator(), $this->createMock(EventDispatcher::class)))
224215
->createFromType('foo');
225216
}

tests/Unit/TwigTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212

1313
namespace Tests\Unit;
1414

15+
use Omines\DataTablesBundle\Exception\MissingDependencyException;
1516
use Omines\DataTablesBundle\Twig\DataTablesExtension;
1617
use Omines\DataTablesBundle\Twig\TwigRenderer;
1718
use PHPUnit\Framework\TestCase;
1819
use Symfony\Component\Translation\Translator;
19-
use Symfony\Component\Translation\TranslatorInterface;
20+
use Symfony\Contracts\Translation\TranslatorInterface;
2021

2122
/**
2223
* TwigTest.
@@ -34,12 +35,11 @@ public function testExtensionName()
3435
$this->assertSame('DataTablesBundle', $twig->getName());
3536
}
3637

37-
/**
38-
* @expectedException \LogicException
39-
* @expectedExceptionMessage You must have symfony/twig-bundle installed
40-
*/
4138
public function testMissingTwigBundleThrows()
4239
{
40+
$this->expectException(MissingDependencyException::class);
41+
$this->expectExceptionMessage('You must have symfony/twig-bundle installed');
42+
4343
new TwigRenderer();
4444
}
4545
}

0 commit comments

Comments
 (0)