How to use testClass method of mock class

Best Atoum code snippet using mock.testClass

FormHelperTest.php

Source:FormHelperTest.php Github

copy

Full Screen

...88 {89 $element = $this->getMock('Zend\Form\Element\Checkbox');90 $name = 'tester';91 $attributes = [92 'class' => 'testClass',93 ];94 $element->expects($this->once())95 ->method('getName')96 ->willReturn($name);97 $element->expects($this->once())98 ->method('getAttributes')99 ->willReturn($attributes);100 $result = $this->helper->checkbox($element);101 $this->assertSame('<input class="testClass" name="tester" type="checkbox" value="">', $result);102 }103 public function testColor()104 {105 $element = $this->getMock('Zend\Form\Element\Color');106 $name = 'tester';107 $attributes = [108 ];109 $element->expects($this->once())110 ->method('getName')111 ->willReturn($name);112 $element->expects($this->once())113 ->method('getAttributes')114 ->willReturn($attributes);115 $result = $this->helper->color($element);116 $this->assertSame('<input name="tester" type="color" value="">', $result);117 }118 public function testColorWithAttributes()119 {120 $element = $this->getMock('Zend\Form\Element\Color');121 $name = 'tester';122 $attributes = [123 'class' => 'testClass',124 ];125 $element->expects($this->once())126 ->method('getName')127 ->willReturn($name);128 $element->expects($this->once())129 ->method('getAttributes')130 ->willReturn($attributes);131 $result = $this->helper->color($element);132 $this->assertSame('<input class="testClass" name="tester" type="color" value="">', $result);133 }134 public function testDate()135 {136 $element = $this->getMock('Zend\Form\Element\Date');137 $name = 'tester';138 $attributes = [139 ];140 $element->expects($this->once())141 ->method('getName')142 ->willReturn($name);143 $element->expects($this->once())144 ->method('getAttributes')145 ->willReturn($attributes);146 $result = $this->helper->date($element);147 $this->assertSame('<input name="tester" type="date" value="">', $result);148 }149 public function testDateWithAttributes()150 {151 $element = $this->getMock('Zend\Form\Element\Date');152 $name = 'tester';153 $attributes = [154 'class' => 'testClass',155 ];156 $element->expects($this->once())157 ->method('getName')158 ->willReturn($name);159 $element->expects($this->once())160 ->method('getAttributes')161 ->willReturn($attributes);162 $result = $this->helper->date($element);163 $this->assertSame('<input class="testClass" name="tester" type="date" value="">', $result);164 }165 public function testDateTime()166 {167 $element = $this->getMock('Zend\Form\Element\DateTime');168 $name = 'tester';169 $attributes = [170 ];171 $element->expects($this->once())172 ->method('getName')173 ->willReturn($name);174 $element->expects($this->once())175 ->method('getAttributes')176 ->willReturn($attributes);177 $result = $this->helper->dateTime($element);178 $this->assertSame('<input name="tester" type="datetime" value="">', $result);179 }180 public function testDateTimeWithAttributes()181 {182 $element = $this->getMock('Zend\Form\Element\DateTime');183 $name = 'tester';184 $attributes = [185 'class' => 'testClass',186 ];187 $element->expects($this->once())188 ->method('getName')189 ->willReturn($name);190 $element->expects($this->once())191 ->method('getAttributes')192 ->willReturn($attributes);193 $result = $this->helper->dateTime($element);194 $this->assertSame('<input class="testClass" name="tester" type="datetime" value="">', $result);195 }196 public function testDateTimeLocal()197 {198 $element = $this->getMock('Zend\Form\Element\DateTimeLocal');199 $name = 'tester';200 $attributes = [201 ];202 $element->expects($this->once())203 ->method('getName')204 ->willReturn($name);205 $element->expects($this->once())206 ->method('getAttributes')207 ->willReturn($attributes);208 $result = $this->helper->dateTimeLocal($element);209 $this->assertSame('<input name="tester" type="datetime-local" value="">', $result);210 }211 public function testDateTimeLocalWithAttributes()212 {213 $element = $this->getMock('Zend\Form\Element\DateTimeLocal');214 $name = 'tester';215 $attributes = [216 'class' => 'testClass',217 ];218 $element->expects($this->once())219 ->method('getName')220 ->willReturn($name);221 $element->expects($this->once())222 ->method('getAttributes')223 ->willReturn($attributes);224 $result = $this->helper->dateTimeLocal($element);225 $this->assertSame('<input class="testClass" name="tester" type="datetime-local" value="">', $result);226 }227 public function testParentClassName()228 {229 $element = 'Zend\Form\Element\Date';230 $result = $this->helper->parentClassName($element);231 $this->assertSame('Zend\Form\Element\DateTime', $result);232 }233 public function testParentClassNameClassNotExisting()234 {235 $element = 'NonExistingClass';236 $result = $this->helper->parentClassName($element);237 $this->assertFalse($result);238 }239 public function testFormElementErrors()240 {241 /** @var \Zend\Form\Element\Text $element */242 $element = $this->getMock('Zend\Form\Element\Text');243 $messages = [244 'key' => 'errorMessage'245 ];246 $element->expects($this->once())247 ->method('getMessages')248 ->willReturn($messages);249 $result = $this->helper->elementErrors($element);250 $this->assertSame('<ul><li>errorMessage</li></ul>', $result);251 }252 public function testFormElementErrorsNoMessage()253 {254 /** @var \Zend\Form\Element\Text $element */255 $element = $this->getMock('Zend\Form\Element\Text');256 $messages = [];257 $element->expects($this->once())258 ->method('getMessages')259 ->willReturn($messages);260 $result = $this->helper->elementErrors($element);261 $this->assertSame('', $result);262 }263 public function testEmail()264 {265 $element = $this->getMock('Zend\Form\Element\Email');266 $name = 'tester';267 $attributes = [];268 $element->expects($this->once())269 ->method('getName')270 ->willReturn($name);271 $element->expects($this->once())272 ->method('getAttributes')273 ->willReturn($attributes);274 $result = $this->helper->email($element);275 $this->assertSame('<input name="tester" type="email" value="">', $result);276 }277 public function testEmailWithAttributes()278 {279 $element = $this->getMock('Zend\Form\Element\Email');280 $name = 'tester';281 $attributes = [282 'class' => 'testClass',283 ];284 $element->expects($this->once())285 ->method('getName')286 ->willReturn($name);287 $element->expects($this->once())288 ->method('getAttributes')289 ->willReturn($attributes);290 $result = $this->helper->email($element);291 $this->assertSame('<input class="testClass" name="tester" type="email" value="">', $result);292 }293 public function testFile()294 {295 $element = $this->getMock('Zend\Form\Element\File');296 $name = 'tester';297 $attributes = [];298 $element->expects($this->once())299 ->method('getName')300 ->willReturn($name);301 $element->expects($this->once())302 ->method('getAttributes')303 ->willReturn($attributes);304 $result = $this->helper->file($element);305 $this->assertSame('<input type="file" name="tester">', $result);306 }307 public function testFileWithAttributes()308 {309 $element = $this->getMock('Zend\Form\Element\File');310 $name = 'tester';311 $attributes = [312 'class' => 'testClass',313 ];314 $element->expects($this->once())315 ->method('getName')316 ->willReturn($name);317 $element->expects($this->once())318 ->method('getAttributes')319 ->willReturn($attributes);320 $result = $this->helper->file($element);321 $this->assertSame('<input class="testClass" type="file" name="tester">', $result);322 }323 public function testHidden()324 {325 $element = $this->getMock('Zend\Form\Element\Hidden');326 $name = 'tester';327 $attributes = [];328 $element->expects($this->once())329 ->method('getName')330 ->willReturn($name);331 $element->expects($this->once())332 ->method('getAttributes')333 ->willReturn($attributes);334 $result = $this->helper->hidden($element);335 $this->assertSame('<input name="tester" type="hidden" value="">', $result);336 }337 public function testHiddenWithAttributes()338 {339 $element = $this->getMock('Zend\Form\Element\Hidden');340 $name = 'tester';341 $attributes = [342 'class' => 'testClass',343 ];344 $element->expects($this->once())345 ->method('getName')346 ->willReturn($name);347 $element->expects($this->once())348 ->method('getAttributes')349 ->willReturn($attributes);350 $result = $this->helper->hidden($element);351 $this->assertSame('<input class="testClass" name="tester" type="hidden" value="">', $result);352 }353 public function testImageNoSrc()354 {355 $element = $this->getMock('Zend\Form\Element\Image');356 $this->setExpectedException(357 'Zend\Form\Exception\DomainException',358 'Zend\Form\View\Helper\FormImage::render requires that the element has an assigned src; none discovered'359 );360 $this->helper->image($element);361 }362 public function testImage()363 {364 $element = $this->getMock('Zend\Form\Element\Image');365 $name = 'tester';366 $src = 'testSrc';367 $attributes = [];368 $element->expects($this->once())369 ->method('getName')370 ->willReturn($name);371 $element->expects($this->once())372 ->method('getAttribute')373 ->with('src')374 ->willReturn($src);375 $element->expects($this->once())376 ->method('getAttributes')377 ->willReturn($attributes);378 $result = $this->helper->image($element);379 $this->assertSame('<input name="tester" type="image">', $result);380 }381 public function testImageWithAttributes()382 {383 $element = $this->getMock('Zend\Form\Element\Image');384 $name = 'tester';385 $src = 'testSrc';386 $attributes = [387 'class' => 'testClass',388 ];389 $element->expects($this->once())390 ->method('getName')391 ->willReturn($name);392 $element->expects($this->once())393 ->method('getAttribute')394 ->with('src')395 ->willReturn($src);396 $element->expects($this->once())397 ->method('getAttributes')398 ->willReturn($attributes);399 $result = $this->helper->image($element);400 $this->assertSame('<input class="testClass" name="tester" type="image">', $result);401 }402 public function testLabel()403 {404 $element = $this->getMock('Zend\Form\Element\Text');405 $name = 'tester';406 $label = 'testLabel';407 $element->expects($this->once())408 ->method('getName')409 ->willReturn($name);410 $element->expects($this->once())411 ->method('getLabel')412 ->willReturn($label);413 $result = $this->helper->label($element);414 $this->assertSame('<label for="tester">testLabel</label>', $result);415 }416 public function testMonth()417 {418 $element = $this->getMock('Zend\Form\Element\Month');419 $name = 'tester';420 $attributes = [];421 $element->expects($this->once())422 ->method('getName')423 ->willReturn($name);424 $element->expects($this->once())425 ->method('getAttributes')426 ->willReturn($attributes);427 $result = $this->helper->month($element);428 $this->assertSame('<input name="tester" type="month" value="">', $result);429 }430 public function testMonthWithAttributes()431 {432 $element = $this->getMock('Zend\Form\Element\Month');433 $name = 'tester';434 $attributes = [435 'class' => 'testClass',436 ];437 $element->expects($this->once())438 ->method('getName')439 ->willReturn($name);440 $element->expects($this->once())441 ->method('getAttributes')442 ->willReturn($attributes);443 $result = $this->helper->month($element);444 $this->assertSame('<input class="testClass" name="tester" type="month" value="">', $result);445 }446 public function testMultiCheckbox()447 {448 $element = $this->getMock('Zend\Form\Element\MultiCheckbox');449 $name = 'tester';450 $attributes = [];451 $options = [452 'a' => 'b',453 'c' => 'd',454 ];455 $element->expects($this->once())456 ->method('getName')457 ->willReturn($name);458 $element->expects($this->once())459 ->method('getAttributes')460 ->willReturn($attributes);461 $element->expects($this->once())462 ->method('getValueOptions')463 ->willReturn($options);464 $result = $this->helper->multiCheckbox($element);465 $this->assertSame('<label><input name="tester&#x5B;&#x5D;" type="checkbox" value="a">b</label><label><input name="tester&#x5B;&#x5D;" type="checkbox" value="c">d</label>', $result);466 }467 public function testNumber()468 {469 $element = $this->getMock('Zend\Form\Element\Number');470 $name = 'tester';471 $attributes = [];472 $element->expects($this->once())473 ->method('getName')474 ->willReturn($name);475 $element->expects($this->once())476 ->method('getAttributes')477 ->willReturn($attributes);478 $result = $this->helper->number($element);479 $this->assertSame('<input name="tester" type="number" value="">', $result);480 }481 public function testNumberWithAttributes()482 {483 $element = $this->getMock('Zend\Form\Element\Number');484 $name = 'tester';485 $attributes = [486 'class' => 'testClass',487 ];488 $element->expects($this->once())489 ->method('getName')490 ->willReturn($name);491 $element->expects($this->once())492 ->method('getAttributes')493 ->willReturn($attributes);494 $result = $this->helper->number($element);495 $this->assertSame('<input class="testClass" name="tester" type="number" value="">', $result);496 }497 public function testPassword()498 {499 $element = $this->getMock('Zend\Form\Element\Password');500 $name = 'tester';501 $attributes = [];502 $element->expects($this->once())503 ->method('getName')504 ->willReturn($name);505 $element->expects($this->once())506 ->method('getAttributes')507 ->willReturn($attributes);508 $result = $this->helper->password($element);509 $this->assertSame('<input name="tester" type="password" value="">', $result);510 }511 public function testPasswordWithAttributes()512 {513 $element = $this->getMock('Zend\Form\Element\Password');514 $name = 'tester';515 $attributes = [516 'class' => 'testClass',517 ];518 $element->expects($this->once())519 ->method('getName')520 ->willReturn($name);521 $element->expects($this->once())522 ->method('getAttributes')523 ->willReturn($attributes);524 $result = $this->helper->password($element);525 $this->assertSame('<input class="testClass" name="tester" type="password" value="">', $result);526 }527 public function testRadio()528 {529 $element = $this->getMock('Zend\Form\Element\Radio');530 $name = 'tester';531 $attributes = [];532 $options = [533 'a' => 'b',534 'c' => 'd',535 ];536 $element->expects($this->once())537 ->method('getName')538 ->willReturn($name);539 $element->expects($this->once())540 ->method('getAttributes')541 ->willReturn($attributes);542 $element->expects($this->once())543 ->method('getValueOptions')544 ->willReturn($options);545 $result = $this->helper->radio($element);546 $this->assertSame('<label><input name="tester" type="radio" value="a">b</label><label><input name="tester" type="radio" value="c">d</label>', $result);547 }548 public function testRange()549 {550 $element = $this->getMock('Zend\Form\Element\Range');551 $name = 'tester';552 $attributes = [];553 $element->expects($this->once())554 ->method('getName')555 ->willReturn($name);556 $element->expects($this->once())557 ->method('getAttributes')558 ->willReturn($attributes);559 $result = $this->helper->range($element);560 $this->assertSame('<input name="tester" type="range" value="">', $result);561 }562 public function testRangeWithAttributes()563 {564 $element = $this->getMock('Zend\Form\Element\Range');565 $name = 'tester';566 $attributes = [567 'class' => 'testClass',568 ];569 $element->expects($this->once())570 ->method('getName')571 ->willReturn($name);572 $element->expects($this->once())573 ->method('getAttributes')574 ->willReturn($attributes);575 $result = $this->helper->range($element);576 $this->assertSame('<input class="testClass" name="tester" type="range" value="">', $result);577 }578 public function testReset()579 {580 $element = $this->getMock('Zend\Form\Element\Button');581 $name = 'tester';582 $attributes = [];583 $element->expects($this->once())584 ->method('getName')585 ->willReturn($name);586 $element->expects($this->once())587 ->method('getAttributes')588 ->willReturn($attributes);589 $result = $this->helper->reset($element);590 $this->assertSame('<input name="tester" type="reset" value="">', $result);591 }592 public function testResetWithAttributes()593 {594 $element = $this->getMock('Zend\Form\Element\Button');595 $name = 'tester';596 $attributes = [597 'class' => 'testClass',598 ];599 $element->expects($this->once())600 ->method('getName')601 ->willReturn($name);602 $element->expects($this->once())603 ->method('getAttributes')604 ->willReturn($attributes);605 $result = $this->helper->reset($element);606 $this->assertSame('<input class="testClass" name="tester" type="reset" value="">', $result);607 }608 public function testSearch()609 {610 $element = $this->getMock('Zend\Form\Element\Text');611 $name = 'tester';612 $attributes = [];613 $element->expects($this->once())614 ->method('getName')615 ->willReturn($name);616 $element->expects($this->once())617 ->method('getAttributes')618 ->willReturn($attributes);619 $result = $this->helper->search($element);620 $this->assertSame('<input name="tester" type="search" value="">', $result);621 }622 public function testSearchWithAttributes()623 {624 $element = $this->getMock('Zend\Form\Element\Text');625 $name = 'tester';626 $attributes = [627 'class' => 'testClass',628 ];629 $element->expects($this->once())630 ->method('getName')631 ->willReturn($name);632 $element->expects($this->once())633 ->method('getAttributes')634 ->willReturn($attributes);635 $result = $this->helper->search($element);636 $this->assertSame('<input class="testClass" name="tester" type="search" value="">', $result);637 }638 public function testSelect()639 {640 $element = $this->getMock('Zend\Form\Element\Select');641 $name = 'tester';642 $attributes = [];643 $valueOptions = [644 'a' => 'b',645 'c' => 'd',646 ];647 $element->expects($this->once())648 ->method('getName')649 ->willReturn($name);650 $element->expects($this->once())651 ->method('getValueOptions')652 ->willReturn($valueOptions);653 $element->expects($this->once())654 ->method('getAttributes')655 ->willReturn($attributes);656 $result = $this->helper->select($element);657 $this->assertSame('<select name="tester"><option value="a">b</option>658<option value="c">d</option></select>', $result);659 }660 public function testSelectWithAttributes()661 {662 $element = $this->getMock('Zend\Form\Element\Select');663 $name = 'tester';664 $attributes = [665 'class' => 'testClass',666 ];667 $valueOptions = [668 'a' => 'b',669 'c' => 'd',670 ];671 $element->expects($this->once())672 ->method('getName')673 ->willReturn($name);674 $element->expects($this->once())675 ->method('getValueOptions')676 ->willReturn($valueOptions);677 $element->expects($this->once())678 ->method('getAttributes')679 ->willReturn($attributes);680 $result = $this->helper->select($element);681 $this->assertSame('<select class="testClass" name="tester"><option value="a">b</option>682<option value="c">d</option></select>', $result);683 }684 public function testSubmit()685 {686 $element = $this->getMock('Zend\Form\Element\Button');687 $name = 'tester';688 $attributes = [];689 $element->expects($this->once())690 ->method('getName')691 ->willReturn($name);692 $element->expects($this->once())693 ->method('getAttributes')694 ->willReturn($attributes);695 $result = $this->helper->submit($element);696 $this->assertSame('<input name="tester" type="submit" value="">', $result);697 }698 public function testSubmitWithAttributes()699 {700 $element = $this->getMock('Zend\Form\Element\Button');701 $name = 'tester';702 $attributes = [703 'class' => 'testClass',704 ];705 $element->expects($this->once())706 ->method('getName')707 ->willReturn($name);708 $element->expects($this->once())709 ->method('getAttributes')710 ->willReturn($attributes);711 $result = $this->helper->submit($element);712 $this->assertSame('<input class="testClass" name="tester" type="submit" value="">', $result);713 }714 public function testTel()715 {716 $element = $this->getMock('Zend\Form\Element\Text');717 $name = 'tester';718 $attributes = [];719 $element->expects($this->once())720 ->method('getName')721 ->willReturn($name);722 $element->expects($this->once())723 ->method('getAttributes')724 ->willReturn($attributes);725 $result = $this->helper->tel($element);726 $this->assertSame('<input name="tester" type="tel" value="">', $result);727 }728 public function testTelWithAttributes()729 {730 $element = $this->getMock('Zend\Form\Element\Text');731 $name = 'tester';732 $attributes = [733 'class' => 'testClass',734 ];735 $element->expects($this->once())736 ->method('getName')737 ->willReturn($name);738 $element->expects($this->once())739 ->method('getAttributes')740 ->willReturn($attributes);741 $result = $this->helper->tel($element);742 $this->assertSame('<input class="testClass" name="tester" type="tel" value="">', $result);743 }744 public function testText()745 {746 $element = $this->getMock('Zend\Form\Element\Text');747 $name = 'tester';748 $attributes = [];749 $element->expects($this->once())750 ->method('getName')751 ->willReturn($name);752 $element->expects($this->once())753 ->method('getAttributes')754 ->willReturn($attributes);755 $result = $this->helper->text($element);756 $this->assertSame('<input name="tester" type="text" value="">', $result);757 }758 public function testTextWithAttributes()759 {760 $element = $this->getMock('Zend\Form\Element\Text');761 $name = 'tester';762 $attributes = [763 'class' => 'testClass',764 ];765 $element->expects($this->once())766 ->method('getName')767 ->willReturn($name);768 $element->expects($this->once())769 ->method('getAttributes')770 ->willReturn($attributes);771 $result = $this->helper->text($element);772 $this->assertSame('<input class="testClass" name="tester" type="text" value="">', $result);773 }774 public function testTextarea()775 {776 $element = $this->getMock('Zend\Form\Element\Textarea');777 $name = 'tester';778 $attributes = [];779 $element->expects($this->once())780 ->method('getName')781 ->willReturn($name);782 $element->expects($this->once())783 ->method('getAttributes')784 ->willReturn($attributes);785 $result = $this->helper->textarea($element);786 $this->assertSame('<textarea name="tester"></textarea>', $result);787 }788 public function testTextareaWithAttributes()789 {790 $element = $this->getMock('Zend\Form\Element\Textarea');791 $name = 'tester';792 $attributes = [793 'class' => 'testClass',794 ];795 $element->expects($this->once())796 ->method('getName')797 ->willReturn($name);798 $element->expects($this->once())799 ->method('getAttributes')800 ->willReturn($attributes);801 $result = $this->helper->textarea($element);802 $this->assertSame('<textarea class="testClass" name="tester"></textarea>', $result);803 }804 public function testTime()805 {806 $element = $this->getMock('Zend\Form\Element\Text');807 $name = 'tester';808 $attributes = [];809 $element->expects($this->once())810 ->method('getName')811 ->willReturn($name);812 $element->expects($this->once())813 ->method('getAttributes')814 ->willReturn($attributes);815 $result = $this->helper->time($element);816 $this->assertSame('<input name="tester" type="time" value="">', $result);817 }818 public function testTimeWithAttributes()819 {820 $element = $this->getMock('Zend\Form\Element\Text');821 $name = 'tester';822 $attributes = [823 'class' => 'testClass',824 ];825 $element->expects($this->once())826 ->method('getName')827 ->willReturn($name);828 $element->expects($this->once())829 ->method('getAttributes')830 ->willReturn($attributes);831 $result = $this->helper->time($element);832 $this->assertSame('<input class="testClass" name="tester" type="time" value="">', $result);833 }834 public function testUrl()835 {836 $element = $this->getMock('Zend\Form\Element\Url');837 $name = 'tester';838 $attributes = [];839 $element->expects($this->once())840 ->method('getName')841 ->willReturn($name);842 $element->expects($this->once())843 ->method('getAttributes')844 ->willReturn($attributes);845 $result = $this->helper->url($element);846 $this->assertSame('<input name="tester" type="url" value="">', $result);847 }848 public function testUrlWithAttributes()849 {850 $element = $this->getMock('Zend\Form\Element\Url');851 $name = 'tester';852 $attributes = [853 'class' => 'testClass',854 ];855 $element->expects($this->once())856 ->method('getName')857 ->willReturn($name);858 $element->expects($this->once())859 ->method('getAttributes')860 ->willReturn($attributes);861 $result = $this->helper->url($element);862 $this->assertSame('<input class="testClass" name="tester" type="url" value="">', $result);863 }864 public function testWeek()865 {866 $element = $this->getMock('Zend\Form\Element\Week');867 $name = 'tester';868 $attributes = [];869 $element->expects($this->once())870 ->method('getName')871 ->willReturn($name);872 $element->expects($this->once())873 ->method('getAttributes')874 ->willReturn($attributes);875 $result = $this->helper->week($element);876 $this->assertSame('<input name="tester" type="week" value="">', $result);877 }878 public function testWeekWithAttributes()879 {880 $element = $this->getMock('Zend\Form\Element\Week');881 $name = 'tester';882 $attributes = [883 'class' => 'testClass',884 ];885 $element->expects($this->once())886 ->method('getName')887 ->willReturn($name);888 $element->expects($this->once())889 ->method('getAttributes')890 ->willReturn($attributes);891 $result = $this->helper->week($element);892 $this->assertSame('<input class="testClass" name="tester" type="week" value="">', $result);893 }894}...

Full Screen

Full Screen

ConvenienceTest.php

Source:ConvenienceTest.php Github

copy

Full Screen

1<?php2/**3 * Copyright (c) Tony Bogdanov <support@tonybogdanov.com>4 *5 * For the full copyright and license information, please view the LICENSE6 * file that was distributed with this source code.7 */8namespace TonyBogdanov\MockableAnnotations\Test\Reader\MockableReader;9use Doctrine\Common\Annotations\AnnotationException;10use Doctrine\Common\Annotations\AnnotationReader;11use TonyBogdanov\MockableAnnotations\MockProvider\ClassMockProvider;12use TonyBogdanov\MockableAnnotations\MockProvider\ClassMockProvider\Filter\ClassNameFilter;13use TonyBogdanov\MockableAnnotations\MockProvider\ClassMockProvider\Strategy\MergeStrategy as ClassMergeStrategy;14use TonyBogdanov\MockableAnnotations\MockProvider\ClassMockProvider\Strategy\OverrideStrategy as ClassOverrideStrategy;15use TonyBogdanov\MockableAnnotations\MockProvider\MethodMockProvider;16use TonyBogdanov\MockableAnnotations\MockProvider\MethodMockProvider\Filter\MethodNameFilter;17use TonyBogdanov\MockableAnnotations\MockProvider\PropertyMockProvider\Filter\PropertyNameFilter;18use TonyBogdanov\MockableAnnotations\MockProvider\MethodMockProvider\Strategy\MergeStrategy as MethodMergeStrategy;19use TonyBogdanov\MockableAnnotations\MockProvider\MethodMockProvider\Strategy\OverrideStrategy as MethodOverrideStrategy;20use TonyBogdanov\MockableAnnotations\MockProvider\PropertyMockProvider;21use TonyBogdanov\MockableAnnotations\MockProvider\PropertyMockProvider\Strategy\MergeStrategy as PropertyMergeStrategy;22use TonyBogdanov\MockableAnnotations\MockProvider\PropertyMockProvider\Strategy\OverrideStrategy as PropertyOverrideStrategy;23use TonyBogdanov\MockableAnnotations\Reader\MockableReader;24use TonyBogdanov\MockableAnnotations\Test\AbstractTestCase;25use TonyBogdanov\MockableAnnotations\Test\Helper\AliasClass;26use TonyBogdanov\MockableAnnotations\Test\Helper\Annotation\TestClassAnnotation;27use TonyBogdanov\MockableAnnotations\Test\Helper\Annotation\TestMethodAnnotation;28use TonyBogdanov\MockableAnnotations\Test\Helper\Annotation\TestPropertyAnnotation;29use TonyBogdanov\MockableAnnotations\Test\Helper\TestClass;30use ReflectionClass;31use ReflectionProperty;32use ReflectionMethod;33use ReflectionException;34/**35 * Class ConvenienceTest36 *37 * @package TonyBogdanov\MockableAnnotations\Test\Reader\MockableReader38 */39class ConvenienceTest extends AbstractTestCase {40 public function provider(): array {41 $classAnnotation = new TestClassAnnotation();42 $classAnnotation->value = 'test';43 $methodAnnotation = new TestMethodAnnotation();44 $methodAnnotation->value = 'test';45 $propertyAnnotation = new TestPropertyAnnotation();46 $propertyAnnotation->value = 'test';47 $aliasClassAnnotation = new TestClassAnnotation();48 $aliasClassAnnotation->value = 'aliased';49 $aliasMethodAnnotation = new TestMethodAnnotation();50 $aliasMethodAnnotation->value = 'aliased';51 $aliasPropertyAnnotation = new TestPropertyAnnotation();52 $aliasPropertyAnnotation->value = 'aliased';53 return [ [54 'override',55 'Class',56 [ TestClass::class, [ $classAnnotation ] ],57 new ClassMockProvider(58 [ $classAnnotation ],59 new ClassOverrideStrategy(),60 new ClassNameFilter( TestClass::class ),61 12362 )63 ], [64 'overrideAlias',65 'Class',66 [ TestClass::class, AliasClass::class ],67 new ClassMockProvider(68 [ $aliasClassAnnotation ],69 new ClassOverrideStrategy(),70 new ClassNameFilter( TestClass::class ),71 12372 )73 ], [74 'merge',75 'Class',76 [ TestClass::class, [ $classAnnotation ] ],77 new ClassMockProvider(78 [ $classAnnotation ],79 new ClassMergeStrategy(),80 new ClassNameFilter( TestClass::class ),81 12382 )83 ], [84 'mergeAlias',85 'Class',86 [ TestClass::class, AliasClass::class ],87 new ClassMockProvider(88 [ $aliasClassAnnotation ],89 new ClassMergeStrategy(),90 new ClassNameFilter( TestClass::class ),91 12392 )93 ], [94 'override',95 'Method',96 [ TestClass::class, 'method', [ $methodAnnotation ] ],97 new MethodMockProvider(98 [ $methodAnnotation ],99 new MethodOverrideStrategy(),100 new MethodNameFilter( TestClass::class, 'method' ),101 123102 )103 ], [104 'overrideAlias',105 'Method',106 [ TestClass::class, 'method', AliasClass::class, 'method' ],107 new MethodMockProvider(108 [ $aliasMethodAnnotation ],109 new MethodOverrideStrategy(),110 new MethodNameFilter( TestClass::class, 'method' ),111 123112 )113 ], [114 'merge',115 'Method',116 [ TestClass::class, 'method', [ $methodAnnotation ] ],117 new MethodMockProvider(118 [ $methodAnnotation ],119 new MethodMergeStrategy(),120 new MethodNameFilter( TestClass::class, 'method' ),121 123122 )123 ], [124 'mergeAlias',125 'Method',126 [ TestClass::class, 'method', AliasClass::class, 'method' ],127 new MethodMockProvider(128 [ $aliasMethodAnnotation ],129 new MethodMergeStrategy(),130 new MethodNameFilter( TestClass::class, 'method' ),131 123132 )133 ], [134 'override',135 'Property',136 [ TestClass::class, 'property', [ $propertyAnnotation ] ],137 new PropertyMockProvider(138 [ $propertyAnnotation ],139 new PropertyOverrideStrategy(),140 new PropertyNameFilter( TestClass::class, 'property' ),141 123142 )143 ], [144 'overrideAlias',145 'Property',146 [ TestClass::class, 'property', AliasClass::class, 'property' ],147 new PropertyMockProvider(148 [ $aliasPropertyAnnotation ],149 new PropertyOverrideStrategy(),150 new PropertyNameFilter( TestClass::class, 'property' ),151 123152 )153 ], [154 'merge',155 'Property',156 [ TestClass::class, 'property', [ $propertyAnnotation ] ],157 new PropertyMockProvider(158 [ $propertyAnnotation ],159 new PropertyMergeStrategy(),160 new PropertyNameFilter( TestClass::class, 'property' ),161 123162 )163 ], [164 'mergeAlias',165 'Property',166 [ TestClass::class, 'property', AliasClass::class, 'property' ],167 new PropertyMockProvider(168 [ $aliasPropertyAnnotation ],169 new PropertyMergeStrategy(),170 new PropertyNameFilter( TestClass::class, 'property' ),171 123172 )173 ] ];174 }175 /**176 * @dataProvider provider177 *178 * @param string $strategy179 * @param string $type180 * @param array $args181 * @param object $expectedProvider182 *183 * @throws AnnotationException184 */185 public function testConvenience(186 string $strategy,187 string $type,188 array $args,189 object $expectedProvider190 ) {191 $reader = new MockableReader( new AnnotationReader() );192 $method = $strategy . $type . 'Annotations';193 $getter = 'get' . $type . 'MockProviders';194 $this->assertSame( $reader, call_user_func_array( [ $reader, $method ], array_merge( $args, [ 123 ] ) ) );195 $this->assertEquals( [ $expectedProvider ], call_user_func( [ $reader, $getter ] ) );196 }197 /**198 * @throws AnnotationException199 * @throws ReflectionException200 */201 public function testOverrideAlias() {202 $reader = new MockableReader( new AnnotationReader() );203 $reader->overrideAliasAnnotations( TestClass::class, AliasClass::class );204 $classAnnotations = $reader->getClassAnnotations( new ReflectionClass( TestClass::class ) );205 $this->assertCount( 1, $classAnnotations );206 $this->assertInstanceOf( TestClassAnnotation::class, $classAnnotations[0] );207 $this->assertSame( 'aliased', $classAnnotations[0]->value );208 $methodAnnotations = $reader->getMethodAnnotations( new ReflectionMethod( TestClass::class, 'method' ) );209 $this->assertCount( 1, $methodAnnotations );210 $this->assertInstanceOf( TestMethodAnnotation::class, $methodAnnotations[0] );211 $this->assertSame( 'aliased', $methodAnnotations[0]->value );212 $propAnnotations = $reader->getPropertyAnnotations( new ReflectionProperty( TestClass::class, 'property' ) );213 $this->assertCount( 1, $propAnnotations );214 $this->assertInstanceOf( TestPropertyAnnotation::class, $propAnnotations[0] );215 $this->assertSame( 'aliased', $propAnnotations[0]->value );216 }217 /**218 * @throws AnnotationException219 * @throws ReflectionException220 */221 public function testMergeAlias() {222 $reader = new MockableReader( new AnnotationReader() );223 $reader->mergeAliasAnnotations( TestClass::class, AliasClass::class );224 $classAnnotations = $reader->getClassAnnotations( new ReflectionClass( TestClass::class ) );225 $this->assertCount( 2, $classAnnotations );226 $this->assertInstanceOf( TestClassAnnotation::class, $classAnnotations[0] );227 $this->assertInstanceOf( TestClassAnnotation::class, $classAnnotations[1] );228 $this->assertSame( 'declared', $classAnnotations[0]->value );229 $this->assertSame( 'aliased', $classAnnotations[1]->value );230 $methodAnnotations = $reader->getMethodAnnotations( new ReflectionMethod( TestClass::class, 'method' ) );231 $this->assertCount( 2, $methodAnnotations );232 $this->assertInstanceOf( TestMethodAnnotation::class, $methodAnnotations[0] );233 $this->assertInstanceOf( TestMethodAnnotation::class, $methodAnnotations[1] );234 $this->assertSame( 'declared', $methodAnnotations[0]->value );235 $this->assertSame( 'aliased', $methodAnnotations[1]->value );236 $propAnnotations = $reader->getPropertyAnnotations( new ReflectionProperty( TestClass::class, 'property' ) );237 $this->assertCount( 2, $propAnnotations );238 $this->assertInstanceOf( TestPropertyAnnotation::class, $propAnnotations[0] );239 $this->assertInstanceOf( TestPropertyAnnotation::class, $propAnnotations[1] );240 $this->assertSame( 'declared', $propAnnotations[0]->value );241 $this->assertSame( 'aliased', $propAnnotations[1]->value );242 }243}...

Full Screen

Full Screen

EntityToIdTransformerTest.php

Source:EntityToIdTransformerTest.php Github

copy

Full Screen

1<?php2namespace Oro\Bundle\FormBundle\Tests\Unit\Form\Type;3use Doctrine\ORM\EntityManager;4use Doctrine\ORM\EntityRepository;5use Oro\Bundle\FormBundle\Form\DataTransformer\EntityToIdTransformer;6use Doctrine\ORM\Mapping\MappingException;7class EntityToIdTransformerTest extends \PHPUnit_Framework_TestCase8{9 protected $entityManager;10 protected $repository;11 /**12 * @dataProvider transformDataProvider13 *14 * @param string $property15 * @param mixed $value16 * @param mixed $expectedValue17 */18 public function testTransform($property, $value, $expectedValue)19 {20 $transformer = new EntityToIdTransformer($this->getMockEntityManager(), 'TestClass', $property, null);21 $this->assertEquals($expectedValue, $transformer->transform($value));22 }23 /**24 * @return array25 */26 public function transformDataProvider()27 {28 return array(29 'default' => array(30 'id',31 $this->createMockEntity('id', 1),32 133 ),34 'empty' => array(35 'id',36 null,37 null38 ),39 );40 }41 /**42 * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException43 * @expectedExceptionMessageExpected Expected argument of type "array", "string" given44 */45 public function testTransformFailsWhenValueInNotAnArray()46 {47 $transformer = new EntityToIdTransformer($this->getMockEntityManager(), 'TestClass', 'id', null);48 $transformer->transform('invalid value');49 }50 public function testReverseTransformEmpty()51 {52 $transformer = new EntityToIdTransformer($this->getMockEntityManager(), 'TestClass', 'id', null);53 $this->assertNull($transformer->reverseTransform(''));54 }55 public function testReverseTransform()56 {57 $entity = $this->createMockEntity('id', 1);58 $repository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')59 ->disableOriginalConstructor()60 ->getMock();61 $repository->expects($this->once())62 ->method('find')63 ->with(1)64 ->will($this->returnValue($entity));65 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')66 ->disableOriginalConstructor()67 ->getMock();68 $em->expects($this->once())69 ->method('getRepository')70 ->with('TestClass')71 ->will($this->returnValue($repository));72 $transformer = new EntityToIdTransformer($em, 'TestClass', 'id', null);73 $this->assertEquals($entity, $transformer->reverseTransform(1));74 }75 /**76 * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException77 * @expectedExceptionMessage The value "1" does not exist or not unique.78 */79 public function testReverseTransformFailsNotFindEntity()80 {81 $repository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')82 ->disableOriginalConstructor()83 ->getMock();84 $repository->expects($this->once())85 ->method('find')86 ->with(1)87 ->will($this->returnValue(null));88 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')89 ->disableOriginalConstructor()90 ->getMock();91 $em->expects($this->once())92 ->method('getRepository')93 ->with('TestClass')94 ->will($this->returnValue($repository));95 $transformer = new EntityToIdTransformer($em, 'TestClass', 'id', null);96 $transformer->reverseTransform(1);97 }98 public function testReverseTransformQueryBuilder()99 {100 $entity = $this->createMockEntity('id', 1);101 $repository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')102 ->disableOriginalConstructor()103 ->getMock();104 $self= $this;105 $callback = function ($pRepository, $pId) use ($self, $repository, $entity) {106 $self->assertEquals($repository, $pRepository);107 $self->assertEquals(1, $pId);108 $query = $self->getMockBuilder('Doctrine\ORM\AbstractQuery')109 ->disableOriginalConstructor()110 ->setMethods(array('execute'))111 ->getMockForAbstractClass();112 $query->expects($self->once())113 ->method('execute')114 ->will($self->returnValue([$entity]));115 $qb = $self->getMockBuilder('Doctrine\ORM\QueryBuilder')116 ->disableOriginalConstructor()117 ->getMock();118 $qb->expects($self->once())119 ->method('getQuery')120 ->will($self->returnValue($query));121 return $qb;122 };123 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')124 ->disableOriginalConstructor()125 ->getMock();126 $em->expects($this->once())127 ->method('getRepository')128 ->with('TestClass')129 ->will($this->returnValue($repository));130 $transformer = new EntityToIdTransformer($em, 'TestClass', 'id', $callback);131 $this->assertEquals($entity, $transformer->reverseTransform(1));132 }133 /**134 * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException135 * @expectedExceptionMessage The value "1" does not exist or not unique.136 */137 public function testReverseTransformTransformationFailedException()138 {139 $repository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')140 ->disableOriginalConstructor()141 ->getMock();142 $self = $this;143 $callback = function () use ($self) {144 $query = $self->getMockBuilder('Doctrine\ORM\AbstractQuery')145 ->disableOriginalConstructor()146 ->setMethods(array('execute'))147 ->getMockForAbstractClass();148 $query->expects($self->once())149 ->method('execute')150 ->will($self->returnValue([]));151 $qb = $self->getMockBuilder('Doctrine\ORM\QueryBuilder')152 ->disableOriginalConstructor()153 ->getMock();154 $qb->expects($self->once())155 ->method('getQuery')156 ->will($self->returnValue($query));157 return $qb;158 };159 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')160 ->disableOriginalConstructor()161 ->getMock();162 $em->expects($this->once())163 ->method('getRepository')164 ->with('TestClass')165 ->will($this->returnValue($repository));166 $transformer = new EntityToIdTransformer($em, 'TestClass', 'id', $callback, true);167 $transformer->reverseTransform(1);168 }169 /**170 * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException171 * @expectedExceptionMessage Expected argument of type "Doctrine\ORM\QueryBuilder", "NULL" given172 */173 public function testReverseTransformQueryBuilderUnexpectedTypeException()174 {175 $entity = $this->createMockEntity('id', 1);176 $repository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')177 ->disableOriginalConstructor()178 ->getMock();179 $callback = function () {180 return null;181 };182 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')183 ->disableOriginalConstructor()184 ->getMock();185 $em->expects($this->once())186 ->method('getRepository')187 ->with('TestClass')188 ->will($this->returnValue($repository));189 $transformer = new EntityToIdTransformer($em, 'TestClass', 'id', $callback);190 $this->assertEquals($entity, $transformer->reverseTransform(1));191 }192 public function testPropertyConstruction()193 {194 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')195 ->disableOriginalConstructor()196 ->getMock();197 $metadata = $this->getMockBuilder('\Doctrine\ORM\Mapping\ClassMetadata')198 ->disableOriginalConstructor()199 ->getMock();200 $metadata->expects($this->once())201 ->method('getSingleIdentifierFieldName')202 ->will($this->returnValue('id'));203 $em->expects($this->once())204 ->method('getClassMetadata')205 ->will($this->returnValue($metadata));206 new EntityToIdTransformer($em, 'TestClass', null, null);207 }208 /**209 * @expectedException \Oro\Bundle\FormBundle\Form\Exception\FormException210 * @expectedExceptionMessage Cannot get id property path of entity. "TestClass" has composite primary key.211 */212 public function testPropertyConstructionException()213 {214 $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')215 ->disableOriginalConstructor()216 ->getMock();217 $metadata = $this->getMockBuilder('\Doctrine\ORM\Mapping\ClassMetadata')218 ->disableOriginalConstructor()219 ->getMock();220 $metadata->expects($this->once())221 ->method('getSingleIdentifierFieldName')222 ->will(223 $this->returnCallback(224 function () {225 throw new MappingException('Exception');226 }227 )228 );229 $em->expects($this->once())230 ->method('getClassMetadata')231 ->will($this->returnValue($metadata));232 new EntityToIdTransformer($em, 'TestClass', null, null);233 }234 /**235 * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException236 * @expectedExceptionMessage Expected argument of type "callable", "string" given237 */238 public function testCallbackException()239 {240 new EntityToIdTransformer($this->getMockEntityManager(), 'TestClass', 'id', 'uncallable');241 }242 /**243 * @return EntityManager|\PHPUnit_Framework_MockObject_MockObject244 */245 protected function getMockEntityManager()246 {247 if (!$this->entityManager) {248 $this->entityManager = $this->getMockBuilder('Doctrine\ORM\EntityManager')249 ->disableOriginalConstructor()250 ->setMethods(array('getClassMetadata', 'getRepository'))251 ->getMockForAbstractClass();252 }253 return $this->entityManager;254 }255 /**256 * Create mock entity by id property name and value257 *258 * @param string $property259 * @param mixed $value260 * @return \PHPUnit_Framework_MockObject_MockObject261 */262 private function createMockEntity($property, $value)263 {264 $getter = 'get' . ucfirst($property);265 $result = $this->getMock('MockEntity', array($getter));266 $result->expects($this->any())->method($getter)->will($this->returnValue($value));267 return $result;268 }269}...

Full Screen

Full Screen

testClass

Using AI Code Generation

copy

Full Screen

1$obj = new testClass();2$obj->testMethod();3$obj = new testClass();4$obj->testMethod();5$obj = new testClass();6$obj->testMethod();7$obj = new testClass();8$obj->testMethod();9$obj = new testClass();10$obj->testMethod();11$obj = new testClass();12$obj->testMethod();13$obj = new testClass();14$obj->testMethod();15$obj = new testClass();16$obj->testMethod();17$obj = new testClass();18$obj->testMethod();19$obj = new testClass();20$obj->testMethod();21$obj = new testClass();22$obj->testMethod();23$obj = new testClass();24$obj->testMethod();25$obj = new testClass();26$obj->testMethod();27$obj = new testClass();28$obj->testMethod();29$obj = new testClass();30$obj->testMethod();31$obj = new testClass();32$obj->testMethod();33$obj = new testClass();34$obj->testMethod();

Full Screen

Full Screen

testClass

Using AI Code Generation

copy

Full Screen

1$mock = new mockClass();2$mock->testClass();3$mock = new mockClass();4$mock->testClass();5$mock = new mockClass();6$mock->testClass();7$mock = new mockClass();8$mock->testClass();9$mock = new mockClass();10$mock->testClass();11$mock = new mockClass();12$mock->testClass();13$mock = new mockClass();14$mock->testClass();15$mock = new mockClass();16$mock->testClass();17$mock = new mockClass();18$mock->testClass();19$mock = new mockClass();20$mock->testClass();21$mock = new mockClass();22$mock->testClass();23$mock = new mockClass();24$mock->testClass();25$mock = new mockClass();26$mock->testClass();27$mock = new mockClass();28$mock->testClass();29$mock = new mockClass();30$mock->testClass();31$mock = new mockClass();32$mock->testClass();

Full Screen

Full Screen

testClass

Using AI Code Generation

copy

Full Screen

1$obj = new testClass();2$obj->testMethod();3class testClass {4 public function testMethod() {5 echo "testMethod";6 }7}8class testClassTest extends PHPUnit_Framework_TestCase {9 public function testMethod() {10 $obj = $this->getMockBuilder('testClass')->getMock();11 $obj->expects($this->once())12 ->method('testMethod')13 ->will($this->returnValue('testMethod'));14 $this->assertEquals('testMethod', $obj->testMethod());15 }16}17$obj = $this->getMockBuilder('testClass')18 ->setMethods(array('testMethod'))19 ->getMock();

Full Screen

Full Screen

testClass

Using AI Code Generation

copy

Full Screen

1$mock = new mockClass();2$mock->testClass();3$mock = new mockClass();4$mock->testClass();5require_once __DIR__ . '/mockClass.php';6require_once __DIR__ . '/mockClass.php';7require_once('mockClass.php');8require_once('mockClass.php');9require_once('mockClass.php');10require_once('mockClass.php');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful