@@ -16,21 +16,6 @@ public function setUp() : void
1616 \CoolBeans \Config::$ validateTableName = false ;
1717 }
1818
19- public function testGetTableName () : void
20- {
21- $ selectionMock = \Mockery::mock (\Nette \Database \Table \Selection::class);
22- $ selectionMock ->expects ('getName ' )->withNoArgs ()->andReturn ('table_name ' );
23-
24- $ activeRowMock = \Mockery::mock (\Nette \Database \Table \ActiveRow::class);
25- $ activeRowMock ->expects ('getPrimary ' )->with (false )->andReturn (['id ' => $ this ->activeRowData ['id ' ]]);
26- $ activeRowMock ->expects ('getTable ' )->withNoArgs ()->andReturn ($ selectionMock );
27-
28- $ beanInstance = new class ($ activeRowMock ) extends \CoolBeans \Bean {
29- };
30-
31- self ::assertEquals ('table_name ' , $ beanInstance ->getTableName ());
32- }
33-
3419 public function testToArray () : void
3520 {
3621 $ activeRowMock = \Mockery::mock (\Nette \Database \Table \ActiveRow::class);
@@ -210,7 +195,6 @@ public function testInitiateProperties() : void
210195 self ::assertEquals (false , $ beanInstance ->offsetGet ('inactive ' ));
211196 self ::assertInstanceOf (\Infinityloop \Utils \Json::class, $ beanInstance ->offsetGet ('json ' ));
212197 self ::assertEquals ('{"id":"1"} ' , $ beanInstance ->offsetGet ('json ' )->toString ());
213- self ::assertEquals (true , (new \ReflectionMethod (\CoolBeans \Bean::class, 'initiateProperties ' ))->isProtected ());
214198 self ::assertEquals (10 , $ beanInstance ->offsetGet ('intPrimaryKey ' )->getValue ());
215199 }
216200
@@ -240,99 +224,4 @@ public function testInitiatePropertiesPropertyWithoutNullable() : void
240224 public bool $ nulled ;
241225 };
242226 }
243-
244- public function testValidateMissingColumns () : void
245- {
246- $ activeRowMock = \Mockery::mock (\Nette \Database \Table \ActiveRow::class);
247- $ activeRowMock ->expects ('offsetGet ' )->with ('id ' )->andReturn ($ this ->activeRowData ['id ' ]);
248- $ activeRowMock ->expects ('toArray ' )->withNoArgs ()->andReturn ($ this ->activeRowData );
249- $ activeRowMock ->expects ('getPrimary ' )->with (false )->andReturn (['id ' => $ this ->activeRowData ['id ' ]]);
250-
251- $ beanInstance = new class ($ activeRowMock ) extends \CoolBeans \Bean {
252- public int $ id ;
253-
254- public function callValidateMissingColumns () : void
255- {
256- $ this ->validateMissingColumns ();
257- }
258- };
259-
260- $ beanInstance ->callValidateMissingColumns ();
261- }
262-
263- public function testValidateMissingColumnsWithoutPropertyDefinition () : void
264- {
265- $ activeRowMock = \Mockery::mock (\Nette \Database \Table \ActiveRow::class);
266- $ activeRowMock ->expects ('toArray ' )->withNoArgs ()->andReturn ($ this ->activeRowData );
267- $ activeRowMock ->expects ('getPrimary ' )->with (false )->andReturn (['id ' => $ this ->activeRowData ['id ' ]]);
268-
269- $ beanInstance = new class ($ activeRowMock ) extends \CoolBeans \Bean {
270- public function callValidateMissingColumns () : void
271- {
272- $ this ->validateMissingColumns ();
273- }
274- };
275-
276- $ this ->expectException (\CoolBeans \Exception \MissingProperty::class);
277- $ this ->expectExceptionMessage ('Property for column [id] is not defined. ' );
278-
279- $ beanInstance ->callValidateMissingColumns ();
280- }
281-
282- public function testValidateTableName () : void
283- {
284- $ selectionMock = \Mockery::mock (\Nette \Database \Table \Selection::class);
285- $ selectionMock ->expects ('getName ' )->withNoArgs ()->andReturn ('test_bean ' );
286-
287- $ activeRowMock = \Mockery::mock (\Nette \Database \Table \ActiveRow::class);
288- $ activeRowMock ->expects ('getTable ' )->withNoArgs ()->andReturn ($ selectionMock );
289- $ activeRowMock ->expects ('getPrimary ' )->with (false )->andReturn (['id ' => $ this ->activeRowData ['id ' ]]);
290-
291- $ testBeanInstance = new \CoolBeans \Tests \Unit \TestBean ($ activeRowMock );
292-
293- $ testBeanInstance ->callValidateTableName ();
294- }
295-
296- public function testValidateTableNameRelatedSyntax () : void
297- {
298- $ selectionMock = \Mockery::mock (\Nette \Database \Table \Selection::class);
299- $ selectionMock ->expects ('getName ' )->withNoArgs ()->andReturn ('user.test_bean ' );
300-
301- $ activeRowMock = \Mockery::mock (\Nette \Database \Table \ActiveRow::class);
302- $ activeRowMock ->expects ('getTable ' )->withNoArgs ()->andReturn ($ selectionMock );
303- $ activeRowMock ->expects ('getPrimary ' )->with (false )->andReturn (['id ' => $ this ->activeRowData ['id ' ]]);
304-
305- $ testBeanInstance = new \CoolBeans \Tests \Unit \TestBean ($ activeRowMock );
306-
307- $ testBeanInstance ->callValidateTableName ();
308- }
309-
310- public function validateTableNameIncorrectNameDataProvider () : array
311- {
312- return [
313- ['TEST_BEAN ' ],
314- ['test_Bean ' ],
315- ['Test_bean ' ],
316- ['Test_Bean ' ],
317- ];
318- }
319-
320- /**
321- * @dataProvider validateTableNameIncorrectNameDataProvider
322- */
323- public function testValidateTableNameIncorrectName (string $ tableName ) : void
324- {
325- $ selectionMock = \Mockery::mock (\Nette \Database \Table \Selection::class);
326- $ selectionMock ->expects ('getName ' )->withNoArgs ()->andReturn ($ tableName );
327-
328- $ activeRowMock = \Mockery::mock (\Nette \Database \Table \ActiveRow::class);
329- $ activeRowMock ->expects ('getTable ' )->withNoArgs ()->andReturn ($ selectionMock );
330- $ activeRowMock ->expects ('getPrimary ' )->with (false )->andReturn (['id ' => $ this ->activeRowData ['id ' ]]);
331-
332- $ testBeanInstance = new \CoolBeans \Tests \Unit \TestBean ($ activeRowMock );
333-
334- $ this ->expectException (\CoolBeans \Exception \InvalidTable::class);
335-
336- $ testBeanInstance ->callValidateTableName ();
337- }
338227}
0 commit comments