2020use Omines \DataTablesBundle \DataTablesBundle ;
2121use Omines \DataTablesBundle \DependencyInjection \DataTablesExtension ;
2222use Omines \DataTablesBundle \DependencyInjection \Instantiator ;
23+ use Omines \DataTablesBundle \Exception \InvalidArgumentException ;
24+ use Omines \DataTablesBundle \Exception \InvalidConfigurationException ;
25+ use Omines \DataTablesBundle \Exception \InvalidStateException ;
2326use Omines \DataTablesBundle \Twig \TwigRenderer ;
2427use PHPUnit \Framework \TestCase ;
2528use Symfony \Component \DependencyInjection \ContainerBuilder ;
2629use Symfony \Component \DependencyInjection \ServiceLocator ;
2730use Symfony \Component \EventDispatcher \EventDispatcher ;
2831use Symfony \Component \HttpFoundation \Request ;
32+ use Symfony \Component \OptionsResolver \Exception \UndefinedOptionsException ;
2933use 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 }
0 commit comments