How to use AnyParameters class

Best Phake code snippet using AnyParameters

DefaultUnitOfWorkTest.php

Source:DefaultUnitOfWorkTest.php Github

copy

Full Screen

1<?php2/*3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.14 *15 * The software is based on the Axon Framework project which is16 * licensed under the Apache 2.0 license. For more information on the Axon Framework17 * see <http://www.axonframework.org/>.18 *19 * This software consists of voluntary contributions made by many individuals20 * and is licensed under the MIT license. For more information, see21 * <http://www.governor-framework.org/>.22 */23namespace Governor\Tests\UnitOfWork;24use Governor\Framework\Domain\GenericEventMessage;25use Governor\Framework\EventHandling\EventListenerInterface;26use Governor\Framework\Domain\AggregateRootInterface;27use Governor\Framework\EventHandling\EventBusInterface;28use Governor\Framework\UnitOfWork\UnitOfWorkListenerAdapter;29use Governor\Framework\UnitOfWork\UnitOfWorkInterface;30use Governor\Framework\UnitOfWork\CurrentUnitOfWork;31use Governor\Framework\UnitOfWork\DefaultUnitOfWork;32use Governor\Framework\UnitOfWork\SaveAggregateCallbackInterface;33use Governor\Framework\UnitOfWork\UnitOfWorkListenerInterface;34use Governor\Framework\UnitOfWork\TransactionManagerInterface;35/**36 * Description of DefaultUnitOfWorkTest37 *38 * @author david39 */40class DefaultUnitOfWorkTest extends \PHPUnit_Framework_TestCase41{42 private $testSubject;43 private $mockEventBus;44 private $mockAggregateRoot;45 private $mockLogger;46 private $event1;47 private $event2;48 private $listener1;49 private $listener2;50 private $callback1;51 private $callback2;52 public function setUp()53 {54 while (CurrentUnitOfWork::isStarted()) {55 CurrentUnitOfWork::get()->rollback();56 }57 $this->event1 = new GenericEventMessage(new TestMessage(1));58 $this->event2 = new GenericEventMessage(new TestMessage(1));59 $this->testSubject = new DefaultUnitOfWork();60 $this->mockEventBus = \Phake::mock(EventBusInterface::class);61 $this->mockAggregateRoot = \Phake::mock(AggregateRootInterface::class);62 $this->listener1 = \Phake::mock(EventListenerInterface::class);63 $this->listener2 = \Phake::mock(EventListenerInterface::class);64 $this->callback1 = \Phake::mock(SaveAggregateCallbackInterface::class);65 $this->callback2 = \Phake::mock(SaveAggregateCallbackInterface::class);66 $self = $this;67 \Phake::when($this->callback1)->save($this->mockAggregateRoot)->thenGetReturnByLambda(function ($aggregate) use($self) {68 CurrentUnitOfWork::get()->publishEvent($self->event1,69 $self->mockEventBus);70 CurrentUnitOfWork::get()->publishEvent($self->event2,71 $self->mockEventBus);72 });73 \Phake::when($this->mockEventBus)->publish(\Phake::anyParameters())->thenGetReturnByLambda(function ($event) use($self) {74 $self->listener1->handle($event[0]);75 $self->listener2->handle($event[0]);76 $self->listener1->handle($event[1]);77 $self->listener2->handle($event[1]);78 });79 }80 public function tearDown()81 {82 $this->assertFalse(CurrentUnitOfWork::isStarted(),83 "A UnitOfWork was not properly cleared");84 }85 public function testTransactionBoundUnitOfWorkLifecycle()86 {87 $mockListener = \Phake::mock(UnitOfWorkListenerInterface::class);88 $mockTransactionManager = \Phake::mock(TransactionManagerInterface::class);89 \Phake::when($mockTransactionManager)->startTransaction()->thenReturn(new \stdClass());90 $uow = DefaultUnitOfWork::startAndGet($mockTransactionManager);91 $uow->registerListener($mockListener);92 \Phake::verify($mockTransactionManager)->startTransaction();93 \Phake::verifyNoInteraction($mockListener);94 $uow->commit();95 \Phake::inOrder(96 \Phake::verify($mockListener)->onPrepareCommit(\Phake::anyParameters()),97 \Phake::verify($mockListener)->onPrepareTransactionCommit(\Phake::equalTo($uow),98 \Phake::anyParameters()),99 \Phake::verify($mockTransactionManager)->commitTransaction(\Phake::anyParameters()),100 \Phake::verify($mockListener)->afterCommit(\Phake::equalTo($uow)),101 \Phake::verify($mockListener)->onCleanup(\Phake::equalTo($uow))102 );103 }104 public function testTransactionBoundUnitOfWorkLifecycle_Rollback()105 {106 $mockListener = \Phake::mock(UnitOfWorkListenerInterface::class);107 $mockTransactionManager = \Phake::mock(TransactionManagerInterface::class);108 \Phake::when($mockTransactionManager)->startTransaction()->thenReturn(new \stdClass());109 $uow = DefaultUnitOfWork::startAndGet($mockTransactionManager);110 $uow->registerListener($mockListener);111 \Phake::verify($mockTransactionManager)->startTransaction();112 \Phake::verifyNoInteraction($mockListener);113 $uow->rollback();114 \Phake::inOrder(115 \Phake::verify($mockTransactionManager)->rollbackTransaction(\Phake::anyParameters()),116 \Phake::verify($mockListener)->onRollback(\Phake::anyParameters()),117 \Phake::verify($mockListener)->onCleanup(\Phake::equalTo($uow))118 );119 }120 public function testUnitOfWorkRegistersListenerWithParent()121 {122 $parentUoW = \Phake::mock(UnitOfWorkInterface::class);123 CurrentUnitOfWork::set($parentUoW);124 $innerUow = DefaultUnitOfWork::startAndGet();125 $innerUow->rollback();126 $parentUoW->rollback();127 CurrentUnitOfWork::clear($parentUoW);128 \Phake::verify($parentUoW)->registerListener(\Phake::anyParameters()); //UnitOfWorkListener 129 }130 public function testInnerUnitOfWorkRolledBackWithOuter()131 {132 $isRolledBack = false;133 $outer = DefaultUnitOfWork::startAndGet();134 $inner = DefaultUnitOfWork::startAndGet();135 $inner->registerListener(new RollbackTestAdapter(function (UnitOfWorkInterface $uow, \Exception $ex = null) use (&$isRolledBack) {136 $isRolledBack = true;137 }));138 $inner->commit();139 $outer->rollback();140 $this->assertTrue($isRolledBack,141 "The inner UoW wasn't properly rolled back");142 $this->assertFalse(CurrentUnitOfWork::isStarted(),143 "The UnitOfWork haven't been correctly cleared");144 }145 public function testInnerUnitOfWorkCommittedBackWithOuter()146 {147 $isCommitted = false;148 $outer = DefaultUnitOfWork::startAndGet();149 $inner = DefaultUnitOfWork::startAndGet();150 $inner->registerListener(new AfterCommitTestAdapter(function (UnitOfWorkInterface $uow) use (&$isCommitted) {151 $isCommitted = true;152 }));153 $inner->commit();154 $this->assertFalse($isCommitted,155 "The inner UoW was committed prematurely");156 $outer->commit();157 $this->assertTrue($isCommitted,158 "The inner UoW wasn't properly committed");159 $this->assertFalse(CurrentUnitOfWork::isStarted(),160 "The UnitOfWork haven't been correctly cleared");161 }162 public function testSagaEventsDoNotOvertakeRegularEvents()163 {164 $this->testSubject->start();165 $self = $this;166 \Phake::when($this->listener1)->handle($this->event1)->thenGetReturnByLambda(function ($event) use($self) {167 $uow = new DefaultUnitOfWork();168 $uow->start();169 $uow->registerAggregate($self->mockAggregateRoot,170 $self->mockEventBus, $self->callback2);171 $uow->commit();172 return null;173 });174 $this->testSubject->registerAggregate($this->mockAggregateRoot,175 $this->mockEventBus, $this->callback1);176 $this->testSubject->commit();177 \Phake::inOrder(178 \Phake::verify($this->listener1, \Phake::times(1))->handle($this->event1),179 \Phake::verify($this->listener2, \Phake::times(1))->handle($this->event1),180 \Phake::verify($this->listener1, \Phake::times(1))->handle($this->event2),181 \Phake::verify($this->listener2, \Phake::times(1))->handle($this->event2)182 );183 }184 public function testUnitOfWorkRolledBackOnCommitFailure_ErrorOnPrepareCommit()185 {186 $mockListener = \Phake::mock(UnitOfWorkListenerInterface::class);187 \Phake::when($mockListener)->onPrepareCommit(\Phake::anyParameters())->thenThrow(new \RuntimeException('phpunit'));188 $this->testSubject->registerListener($mockListener);189 $this->testSubject->start();190 try {191 $this->testSubject->commit();192 $this->fail("Expected exception");193 } catch (\Exception $ex) {194 $this->assertInstanceOf('\RuntimeException', $ex);195 $this->assertEquals('phpunit', $ex->getMessage());196 }197 \Phake::verify($mockListener)->onRollback(\Phake::anyParameters());198 \Phake::verify($mockListener, \Phake::never())->afterCommit(\Phake::anyParameters());199 \Phake::verify($mockListener)->onCleanup(\Phake::anyParameters());200 }201 public function testUnitOfWorkRolledBackOnCommitFailure_ErrorOnCommitAggregate()202 {203 $mockListener = \Phake::mock(UnitOfWorkListenerInterface::class);204 \Phake::when($this->callback1)->save(\Phake::anyParameters())->thenThrow(new \RuntimeException('phpunit'));205 $this->testSubject->registerListener($mockListener);206 $this->testSubject->registerAggregate($this->mockAggregateRoot,207 $this->mockEventBus, $this->callback1);208 $this->testSubject->start();209 try {210 $this->testSubject->commit();211 $this->fail("Expected exception");212 } catch (\RuntimeException $ex) {213 $this->assertInstanceOf('\RuntimeException', $ex,214 "Got an exception, but the wrong one");215 $this->assertEquals('phpunit', $ex->getMessage(),216 "Got an exception, but the wrong one");217 }218 \Phake::verify($mockListener)->onPrepareCommit(\Phake::anyParameters());219 \Phake::verify($mockListener)->onRollback(\Phake::anyParameters());220 \Phake::verify($mockListener, \Phake::never())->afterCommit(\Phake::anyParameters());221 \Phake::verify($mockListener)->onCleanup(\Phake::anyParameters());222 }223 public function testUnitOfWorkRolledBackOnCommitFailure_ErrorOnDispatchEvents()224 {225 $mockListener = \Phake::mock(UnitOfWorkListenerInterface::class);226 \Phake::when($mockListener)->onEventRegistered(\Phake::anyParameters())->thenReturn(new GenericEventMessage(new TestMessage(1)));227 \Phake::when($this->mockEventBus)->publish(\Phake::anyParameters())->thenThrow(new \RuntimeException('phpunit'));228 $this->testSubject->start();229 $this->testSubject->registerListener($mockListener);230 $this->testSubject->publishEvent(new GenericEventMessage(new TestMessage(1)),231 $this->mockEventBus);232 try {233 $this->testSubject->commit();234 $this->fail("Expected exception");235 } catch (\RuntimeException $ex) {236 $this->assertInstanceOf('\RuntimeException', $ex,237 "Got an exception, but the wrong one");238 $this->assertEquals('phpunit', $ex->getMessage(),239 "Got an exception, but the wrong one");240 }241 \Phake::verify($mockListener)->onPrepareCommit(\Phake::anyParameters());242 \Phake::verify($mockListener)->onRollback(\Phake::anyParameters());243 \Phake::verify($mockListener, \Phake::never())->afterCommit(\Phake::anyParameters());244 \Phake::verify($mockListener)->onCleanup(\Phake::anyParameters());245 }246 public function testUnitOfWorkCleanupDelayedUntilOuterUnitOfWorkIsCleanedUp_InnerCommit()247 {248 $outerListener = \Phake::mock(UnitOfWorkListenerInterface::class);249 $innerListener = \Phake::mock(UnitOfWorkListenerInterface::class);250 $outer = DefaultUnitOfWork::startAndGet($this->mockLogger);251 $inner = DefaultUnitOfWork::startAndGet($this->mockLogger);252 $outer->registerListener($outerListener);253 $inner->registerListener($innerListener);254 $inner->commit();255 \Phake::verify($innerListener, \Phake::never())->afterCommit(\Phake::anyParameters());256 \Phake::verify($innerListener, \Phake::never())->onCleanup(\Phake::anyParameters());257 $outer->commit();258 \Phake::inOrder(259 \Phake::verify($innerListener)->afterCommit(\Phake::anyParameters()),260 \Phake::verify($outerListener)->afterCommit(\Phake::anyParameters()),261 \Phake::verify($innerListener)->onCleanup(\Phake::anyParameters()),262 \Phake::verify($outerListener)->onCleanup(\Phake::anyParameters())263 );264 }265 public function testUnitOfWorkCleanupDelayedUntilOuterUnitOfWorkIsCleanedUp_InnerRollback()266 {267 $outerListener = \Phake::mock(UnitOfWorkListenerInterface::class);268 $innerListener = \Phake::mock(UnitOfWorkListenerInterface::class);269 $outer = DefaultUnitOfWork::startAndGet();270 $inner = DefaultUnitOfWork::startAndGet();271 $inner->registerListener($innerListener);272 $outer->registerListener($outerListener);273 $inner->rollback();274 \Phake::verify($innerListener, \Phake::never())->afterCommit(\Phake::anyParameters());275 \Phake::verify($innerListener, \Phake::never())->onCleanup(\Phake::anyParameters());276 $outer->commit();277 \Phake::inOrder(278 \Phake::verify($innerListener)->onRollback(\Phake::anyParameters()),279 \Phake::verify($outerListener)->afterCommit(\Phake::anyParameters()),280 \Phake::verify($innerListener)->onCleanup(\Phake::anyParameters()),281 \Phake::verify($outerListener)->onCleanup(\Phake::anyParameters())282 );283 }284 public function testUnitOfWorkCleanupDelayedUntilOuterUnitOfWorkIsCleanedUp_InnerCommit_OuterRollback()285 {286 $outerListener = \Phake::mock(UnitOfWorkListenerInterface::class);287 $innerListener = \Phake::mock(UnitOfWorkListenerInterface::class);288 $outer = DefaultUnitOfWork::startAndGet();289 $inner = DefaultUnitOfWork::startAndGet();290 $inner->registerListener($innerListener);291 $outer->registerListener($outerListener);292 $inner->commit();293 \Phake::verify($innerListener, \Phake::never())->afterCommit(\Phake::anyParameters());294 \Phake::verify($innerListener, \Phake::never())->onCleanup(\Phake::anyParameters());295 $outer->rollback();296 \Phake::verify($outerListener, \Phake::never())->onPrepareCommit(\Phake::anyParameters());297 \Phake::inOrder(298 \Phake::verify($innerListener)->onPrepareCommit(\Phake::anyParameters()),299 \Phake::verify($innerListener)->onRollback(\Phake::anyParameters()),300 \Phake::verify($outerListener)->onRollback(\Phake::anyParameters()),301 \Phake::verify($innerListener)->onCleanup(\Phake::anyParameters()),302 \Phake::verify($outerListener)->onCleanup(\Phake::anyParameters())303 );304 }305}306class TestMessage307{308 private $text;309 function __construct($text)310 {311 $this->text = $text;312 }313 public function getText()314 {315 return $this->text;316 }317}318class RollbackTestAdapter extends UnitOfWorkListenerAdapter319{320 private $closure;321 public function __construct(\Closure $closure)322 {323 $this->closure = $closure;324 }325 public function onRollback(UnitOfWorkInterface $unitOfWork,326 \Exception $failureCause = null)327 {328 $cb = $this->closure;329 $cb($unitOfWork, $failureCause);330 }331}332class AfterCommitTestAdapter extends UnitOfWorkListenerAdapter333{334 private $closure;335 public function __construct(\Closure $closure)336 {337 $this->closure = $closure;338 }339 public function afterCommit(UnitOfWorkInterface $unitOfWork)340 {341 $cb = $this->closure;342 $cb($unitOfWork);343 }344}...

Full Screen

Full Screen

FileSystemTest.php

Source:FileSystemTest.php Github

copy

Full Screen

1<?php2namespace Icecave\Archer\FileSystem;3use Phake;4use PHPUnit_Framework_TestCase;5class FileSystemTest extends PHPUnit_Framework_TestCase6{7 protected function setUp()8 {9 parent::setUp();10 $this->isolator = Phake::mock('Icecave\Archer\Support\Isolator');11 $this->fileSystem = new FileSystem($this->isolator);12 }13 public function testExists()14 {15 Phake::when($this->isolator)16 ->file_exists(Phake::anyParameters())17 ->thenReturn(true)18 ->thenReturn(false)19 ;20 $this->assertTrue($this->fileSystem->exists('foo'));21 $this->assertFalse($this->fileSystem->exists('bar'));22 Phake::inOrder(23 Phake::verify($this->isolator)->file_exists('foo'),24 Phake::verify($this->isolator)->file_exists('bar')25 );26 }27 public function testExistsFailure()28 {29 Phake::when($this->isolator)30 ->file_exists(Phake::anyParameters())31 ->thenThrow(Phake::mock('ErrorException'))32 ;33 $this->setExpectedException(34 __NAMESPACE__ . '\Exception\ReadException'35 );36 $this->fileSystem->exists('foo');37 }38 public function testFileExists()39 {40 Phake::when($this->isolator)41 ->is_file(Phake::anyParameters())42 ->thenReturn(true)43 ->thenReturn(false)44 ;45 $this->assertTrue($this->fileSystem->fileExists('foo'));46 $this->assertFalse($this->fileSystem->fileExists('bar'));47 Phake::inOrder(48 Phake::verify($this->isolator)->is_file('foo'),49 Phake::verify($this->isolator)->is_file('bar')50 );51 }52 public function testFileExistsFailure()53 {54 Phake::when($this->isolator)55 ->is_file(Phake::anyParameters())56 ->thenThrow(Phake::mock('ErrorException'))57 ;58 $this->setExpectedException(59 __NAMESPACE__ . '\Exception\ReadException'60 );61 $this->fileSystem->fileExists('foo');62 }63 public function testDirectoryExists()64 {65 Phake::when($this->isolator)66 ->is_dir(Phake::anyParameters())67 ->thenReturn(true)68 ->thenReturn(false)69 ;70 $this->assertTrue($this->fileSystem->directoryExists('foo'));71 $this->assertFalse($this->fileSystem->directoryExists('bar'));72 Phake::inOrder(73 Phake::verify($this->isolator)->is_dir('foo'),74 Phake::verify($this->isolator)->is_dir('bar')75 );76 }77 public function testDirectoryExistsFailure()78 {79 Phake::when($this->isolator)80 ->is_dir(Phake::anyParameters())81 ->thenThrow(Phake::mock('ErrorException'))82 ;83 $this->setExpectedException(84 __NAMESPACE__ . '\Exception\ReadException'85 );86 $this->fileSystem->directoryExists('foo');87 }88 public function testRead()89 {90 Phake::when($this->isolator)91 ->file_get_contents(Phake::anyParameters())92 ->thenReturn('bar')93 ;94 $this->assertSame('bar', $this->fileSystem->read('foo'));95 Phake::verify($this->isolator)->file_get_contents('foo');96 }97 public function testReadFailure()98 {99 Phake::when($this->isolator)100 ->file_get_contents(Phake::anyParameters())101 ->thenThrow(Phake::mock('ErrorException'))102 ;103 $this->setExpectedException(104 __NAMESPACE__ . '\Exception\ReadException'105 );106 $this->fileSystem->read('foo');107 }108 public function testListPaths()109 {110 Phake::when($this->isolator)111 ->scandir(Phake::anyParameters())112 ->thenReturn(array('.', '..', 'bar', 'baz'))113 ;114 $this->assertSame(array('bar', 'baz'), $this->fileSystem->listPaths('foo'));115 Phake::verify($this->isolator)->scandir('foo');116 }117 public function testListPathsFailure()118 {119 Phake::when($this->isolator)120 ->scandir(Phake::anyParameters())121 ->thenThrow(Phake::mock('ErrorException'))122 ;123 $this->setExpectedException(124 __NAMESPACE__ . '\Exception\ReadException'125 );126 $this->fileSystem->listPaths('foo');127 }128 public function testWrite()129 {130 Phake::when($this->isolator)131 ->dirname(Phake::anyParameters())132 ->thenReturn('foo')133 ;134 Phake::when($this->isolator)135 ->is_dir(Phake::anyParameters())136 ->thenReturn(true)137 ;138 $this->fileSystem->write('foo/bar', 'baz');139 Phake::inOrder(140 Phake::verify($this->isolator)->dirname('foo/bar'),141 Phake::verify($this->isolator)->is_dir('foo'),142 Phake::verify($this->isolator)->file_put_contents('foo/bar', 'baz')143 );144 Phake::verify($this->isolator, Phake::never())->mkdir(Phake::anyParameters());145 }146 public function testWriteCreateParentDirectory()147 {148 Phake::when($this->isolator)149 ->dirname(Phake::anyParameters())150 ->thenReturn('foo')151 ;152 Phake::when($this->isolator)153 ->is_dir(Phake::anyParameters())154 ->thenReturn(false)155 ;156 $this->fileSystem->write('foo/bar', 'baz');157 Phake::inOrder(158 Phake::verify($this->isolator)->dirname('foo/bar'),159 Phake::verify($this->isolator)->is_dir('foo'),160 Phake::verify($this->isolator)->mkdir('foo', 0777, true),161 Phake::verify($this->isolator)->file_put_contents('foo/bar', 'baz')162 );163 }164 public function testWriteFailure()165 {166 Phake::when($this->isolator)167 ->dirname(Phake::anyParameters())168 ->thenReturn('foo')169 ;170 Phake::when($this->isolator)171 ->is_dir(Phake::anyParameters())172 ->thenReturn(true)173 ;174 Phake::when($this->isolator)175 ->file_put_contents(Phake::anyParameters())176 ->thenThrow(Phake::mock('ErrorException'))177 ;178 $this->setExpectedException(179 __NAMESPACE__ . '\Exception\WriteException'180 );181 $this->fileSystem->write('foo/bar', 'baz');182 }183 public function testWriteFailureDirname()184 {185 Phake::when($this->isolator)186 ->dirname(Phake::anyParameters())187 ->thenThrow(Phake::mock('ErrorException'))188 ;189 $this->setExpectedException(190 __NAMESPACE__ . '\Exception\ReadException'191 );192 $this->fileSystem->write('foo/bar', 'baz');193 }194 public function testCopy()195 {196 Phake::when($this->isolator)197 ->dirname(Phake::anyParameters())198 ->thenReturn('bar')199 ;200 Phake::when($this->isolator)201 ->is_dir(Phake::anyParameters())202 ->thenReturn(true)203 ;204 $this->fileSystem->copy('foo', 'bar/baz');205 Phake::inOrder(206 Phake::verify($this->isolator)->dirname('bar/baz'),207 Phake::verify($this->isolator)->is_dir('bar'),208 Phake::verify($this->isolator)->copy('foo', 'bar/baz')209 );210 Phake::verify($this->isolator, Phake::never())->mkdir(Phake::anyParameters());211 }212 public function testCopyCreateParentDirectory()213 {214 Phake::when($this->isolator)215 ->dirname(Phake::anyParameters())216 ->thenReturn('bar')217 ;218 Phake::when($this->isolator)219 ->is_dir(Phake::anyParameters())220 ->thenReturn(false)221 ;222 $this->fileSystem->copy('foo', 'bar/baz');223 Phake::inOrder(224 Phake::verify($this->isolator)->dirname('bar/baz'),225 Phake::verify($this->isolator)->is_dir('bar'),226 Phake::verify($this->isolator)->mkdir('bar', 0777, true),227 Phake::verify($this->isolator)->copy('foo', 'bar/baz')228 );229 }230 public function testCopyFailure()231 {232 Phake::when($this->isolator)233 ->dirname(Phake::anyParameters())234 ->thenReturn('foo')235 ;236 Phake::when($this->isolator)237 ->is_dir(Phake::anyParameters())238 ->thenReturn(true)239 ;240 Phake::when($this->isolator)241 ->copy(Phake::anyParameters())242 ->thenThrow(Phake::mock('ErrorException'))243 ;244 $this->setExpectedException(245 __NAMESPACE__ . '\Exception\WriteException'246 );247 $this->fileSystem->copy('foo', 'bar/baz');248 }249 public function testCopyFailureDirname()250 {251 Phake::when($this->isolator)252 ->dirname(Phake::anyParameters())253 ->thenThrow(Phake::mock('ErrorException'))254 ;255 $this->setExpectedException(256 __NAMESPACE__ . '\Exception\ReadException'257 );258 $this->fileSystem->copy('foo', 'bar/baz');259 }260 public function testMove()261 {262 Phake::when($this->isolator)263 ->dirname(Phake::anyParameters())264 ->thenReturn('bar')265 ;266 Phake::when($this->isolator)267 ->is_dir(Phake::anyParameters())268 ->thenReturn(true)269 ;270 $this->fileSystem->move('foo', 'bar/baz');271 Phake::inOrder(272 Phake::verify($this->isolator)->dirname('bar/baz'),273 Phake::verify($this->isolator)->is_dir('bar'),274 Phake::verify($this->isolator)->rename('foo', 'bar/baz')275 );276 Phake::verify($this->isolator, Phake::never())->mkdir(Phake::anyParameters());277 }278 public function testMoveCreateParentDirectory()279 {280 Phake::when($this->isolator)281 ->dirname(Phake::anyParameters())282 ->thenReturn('bar')283 ;284 Phake::when($this->isolator)285 ->is_dir(Phake::anyParameters())286 ->thenReturn(false)287 ;288 $this->fileSystem->move('foo', 'bar/baz');289 Phake::inOrder(290 Phake::verify($this->isolator)->dirname('bar/baz'),291 Phake::verify($this->isolator)->is_dir('bar'),292 Phake::verify($this->isolator)->mkdir('bar', 0777, true),293 Phake::verify($this->isolator)->rename('foo', 'bar/baz')294 );295 }296 public function testMoveFailure()297 {298 Phake::when($this->isolator)299 ->dirname(Phake::anyParameters())300 ->thenReturn('foo')301 ;302 Phake::when($this->isolator)303 ->is_dir(Phake::anyParameters())304 ->thenReturn(true)305 ;306 Phake::when($this->isolator)307 ->rename(Phake::anyParameters())308 ->thenThrow(Phake::mock('ErrorException'))309 ;310 $this->setExpectedException(311 __NAMESPACE__ . '\Exception\WriteException'312 );313 $this->fileSystem->move('foo', 'bar/baz');314 }315 public function testMoveFailureDirname()316 {317 Phake::when($this->isolator)318 ->dirname(Phake::anyParameters())319 ->thenThrow(Phake::mock('ErrorException'))320 ;321 $this->setExpectedException(322 __NAMESPACE__ . '\Exception\ReadException'323 );324 $this->fileSystem->move('foo', 'bar/baz');325 }326 public function testCreateDirectory()327 {328 $this->fileSystem->createDirectory('foo');329 Phake::verify($this->isolator)->mkdir('foo', 0777, true);330 }331 public function testCreateDirectoryFailure()332 {333 Phake::when($this->isolator)334 ->mkdir(Phake::anyParameters())335 ->thenThrow(Phake::mock('ErrorException'))336 ;337 $this->setExpectedException(338 __NAMESPACE__ . '\Exception\WriteException'339 );340 $this->fileSystem->createDirectory('foo');341 }342 public function testChmod()343 {344 $this->fileSystem->chmod('foo', 0755);345 Phake::verify($this->isolator)->chmod('foo', 0755);346 }347 public function testChmodFailure()348 {349 Phake::when($this->isolator)350 ->chmod(Phake::anyParameters())351 ->thenThrow(Phake::mock('ErrorException'))352 ;353 $this->setExpectedException(354 __NAMESPACE__ . '\Exception\WriteException'355 );356 $this->fileSystem->chmod('foo', 0755);357 }358 public function testDeleteFile()359 {360 Phake::when($this->isolator)361 ->is_dir(Phake::anyParameters())362 ->thenReturn(false)363 ;364 $this->fileSystem->delete('foo');365 Phake::inOrder(366 Phake::verify($this->isolator)->is_dir('foo'),367 Phake::verify($this->isolator)->unlink('foo')368 );369 Phake::verify($this->isolator, Phake::never())->rmdir(Phake::anyParameters());370 }371 public function testDeleteFileFailure()372 {373 Phake::when($this->isolator)374 ->is_dir(Phake::anyParameters())375 ->thenReturn(false)376 ;377 Phake::when($this->isolator)378 ->unlink(Phake::anyParameters())379 ->thenThrow(Phake::mock('ErrorException'))380 ;381 $this->setExpectedException(382 __NAMESPACE__ . '\Exception\WriteException'383 );384 $this->fileSystem->delete('foo');385 }386 public function testDeleteDirectory()387 {388 Phake::when($this->isolator)389 ->is_dir(Phake::anyParameters())390 ->thenReturn(true)391 ->thenReturn(false)392 ;393 Phake::when($this->isolator)394 ->scandir(Phake::anyParameters())395 ->thenReturn(array('.', '..', 'bar', 'baz'))396 ;397 $this->fileSystem->delete('foo');398 Phake::inOrder(399 Phake::verify($this->isolator)->is_dir('foo'),400 Phake::verify($this->isolator)->scandir('foo'),401 Phake::verify($this->isolator)->is_dir('foo/bar'),402 Phake::verify($this->isolator)->unlink('foo/bar'),403 Phake::verify($this->isolator)->is_dir('foo/baz'),404 Phake::verify($this->isolator)->unlink('foo/baz'),405 Phake::verify($this->isolator)->rmdir('foo')406 );407 Phake::verify($this->isolator, Phake::never())->unlink('foo');408 }409 public function testDeleteDirectoryFailure()410 {411 Phake::when($this->isolator)412 ->is_dir(Phake::anyParameters())413 ->thenReturn(true)414 ;415 Phake::when($this->isolator)416 ->scandir(Phake::anyParameters())417 ->thenReturn(array('.', '..'))418 ;419 Phake::when($this->isolator)420 ->rmdir(Phake::anyParameters())421 ->thenThrow(Phake::mock('ErrorException'))422 ;423 $this->setExpectedException(424 __NAMESPACE__ . '\Exception\WriteException'425 );426 $this->fileSystem->delete('foo');427 }428}...

Full Screen

Full Screen

ExistingLayoutValidatorTest.php

Source:ExistingLayoutValidatorTest.php Github

copy

Full Screen

1<?php2namespace Theodo\RogerCmsBundle\Tests\Validator\Constraints;3use Theodo\RogerCmsBundle\Validator\Constraints\ExistingLayoutValidator;4use Phake;5/**6 * @author Marek Kalnik <marekk@theodo.fr>7 */8class ExistingLayoutValidatorTest extends \PHPUnit_Framework_TestCase9{10 /**11 * @var Twig_LoaderInterface12 */13 public $loader;14 /**15 * @var Theodo\RogerCmsBundle\Validator\Constraints\ExistingLayoutValidator16 */17 public $validator;18 /**19 * @var Theodo\RogerCmsBundle\Form\DataTransformer\LayoutExtractor;20 */21 public $extractor;22 public function setUp()23 {24 $this->loader = Phake::mock('Twig_LoaderInterface');25 $this->extractor = Phake::mock('Theodo\RogerCmsBundle\Form\DataTransformer\LayoutExtractor');26 $this->validator = new ExistingLayoutValidator($this->loader, $this->extractor);27 }28 public function testIsConstraintValidator()29 {30 $this->assertInstanceOf('Symfony\Component\Validator\ConstraintValidatorInterface', $this->validator);31 }32 public function testValidatesIfLayoutExists()33 {34 Phake::when($this->extractor)->getLayout(Phake::anyParameters())35 ->thenReturn('blabla');36 Phake::when($this->loader)->getSource(Phake::anyParameters())37 ->thenReturn('blabla');38 $context = Phake::mock('Symfony\Component\Validator\ExecutionContext');39 $this->validator->initialize($context);40 $this->validator->validate('blabla', Phake::mock('Symfony\Component\Validator\Constraint'));41 Phake::verify($this->extractor, Phake::times(1))42 ->getLayout(Phake::anyParameters());43 Phake::verify($this->loader, Phake::times(1))44 ->getSource(Phake::anyParameters());45 Phake::verify($context, Phake::never())46 ->addViolation(Phake::anyParameters());47 }48 public function testFailsIfLayoutDoesNotExist()49 {50 Phake::when($this->extractor)->getLayout(Phake::anyParameters())51 ->thenReturn('blabla');52 Phake::when($this->loader)->getSource(Phake::anyParameters())53 ->thenThrow(new \Twig_Error_Loader('Template not found'));54 $context = Phake::mock('Symfony\Component\Validator\ExecutionContext');55 $this->validator->initialize($context);56 $this->validator->validate('blabla', Phake::mock('Symfony\Component\Validator\Constraint'));57 Phake::verify($this->loader, Phake::times(1))58 ->getSource(Phake::anyParameters());59 Phake::verify($context, Phake::times(1))60 ->addViolation(Phake::anyParameters());61 }62}...

Full Screen

Full Screen

AnyParameters

Using AI Code Generation

copy

Full Screen

1use Phake\AnyParameters;2{3 public function testSomeMethod()4 {5 $mock = Phake::mock('SomeClass');6 Phake::when($mock)->someMethod(AnyParameters::create())->thenReturn('some value');7 }8}9use Prophecy\Argument;10{11 public function testSomeMethod()12 {13 $mock = $this->prophesize('SomeClass');14 $mock->someMethod(Argument::any())->willReturn('some value');15 }16}17{18 public function testSomeMethod()19 {20 $mock = $this->createMock('SomeClass');21 $mock->expects($this->any())->method('someMethod')->willReturn('some value');22 }23}24use Mockery\Matcher\AnyArgs;25{26 public function testSomeMethod()27 {28 $mock = Mockery::mock('SomeClass');29 $mock->shouldReceive('someMethod')->with(AnyArgs::create())->andReturn('some value');30 }31}32use Prophecy\Argument;33{34 public function testSomeMethod()35 {36 $mock = $this->prophesize('SomeClass');37 $mock->someMethod(Argument::any())->willReturn('some value');38 }39}40{41 public function testSomeMethod()42 {43 $mock = $this->createMock('SomeClass');44 $mock->expects($this->any())->method('someMethod')->willReturn('some value');45 }46}47use Mockery\Matcher\AnyArgs;48{49 public function testSomeMethod()50 {51 $mock = Mockery::mock('Some

Full Screen

Full Screen

AnyParameters

Using AI Code Generation

copy

Full Screen

1require_once __DIR__ . '/../vendor/autoload.php';2use Phake\AnyParameters;3require_once __DIR__ . '/../vendor/autoload.php';4use Phake\AnyParameters;5require_once __DIR__ . '/../vendor/autoload.php';6use Phake\AnyParameters;7require_once __DIR__ . '/../vendor/autoload.php';8use Phake\AnyParameters;9require_once __DIR__ . '/../vendor/autoload.php';10use Phake\AnyParameters;11require_once __DIR__ . '/../vendor/autoload.php';12use Phake\AnyParameters;13require_once __DIR__ . '/../vendor/autoload.php';14use Phake\AnyParameters;15require_once __DIR__ . '/../vendor/autoload.php';16use Phake\AnyParameters;17require_once __DIR__ . '/../vendor/autoload.php';18use Phake\AnyParameters;19require_once __DIR__ . '/../vendor/autoload.php';20use Phake\AnyParameters;21require_once __DIR__ . '/../vendor/autoload.php';22use Phake\AnyParameters;23require_once __DIR__ . '/../vendor/autoload.php';24use Phake\AnyParameters;25require_once __DIR__ . '/../vendor/autoload.php';26use Phake\AnyParameters;27require_once __DIR__ . '/../vendor/autoload.php';28use Phake\AnyParameters;

Full Screen

Full Screen

AnyParameters

Using AI Code Generation

copy

Full Screen

1use Phake\AnyParameters;2$mock = Phake::mock('Class');3Phake::when($mock)->method(AnyParameters::create())->thenReturn('value');4Phake::verify($mock)->method(AnyParameters::create());5use Phake\AnyParameters;6$mock = Phake::mock('Class');7Phake::when($mock)->method(AnyParameters::create())->thenReturn('value');8Phake::verify($mock)->method(AnyParameters::create());9use Phake\AnyParameters;10$mock = Phake::mock('Class');11Phake::when($mock)->method(AnyParameters::create())->thenReturn('value');12Phake::verify($mock)->method(AnyParameters::create());13use Phake\AnyParameters;14$mock = Phake::mock('Class');15Phake::when($mock)->method(AnyParameters::create())->thenReturn('value');16Phake::verify($mock)->method(AnyParameters::create());17use Phake\AnyParameters;18$mock = Phake::mock('Class');19Phake::when($mock)->method(AnyParameters::create())->thenReturn('value');20Phake::verify($mock)->method(AnyParameters::create());21use Phake\AnyParameters;22$mock = Phake::mock('Class');23Phake::when($mock)->method(AnyParameters::create())->thenReturn('value');24Phake::verify($mock)->method(AnyParameters::create());

Full Screen

Full Screen

AnyParameters

Using AI Code Generation

copy

Full Screen

1$anyParameters = new Phake_Matchers_AnyParameters();2$mock = Phake::mock('Hello');3Phake::when($mock)->say($anyParameters)->thenReturn('Hello World');4$anyParameters = new Phake_Matchers_AnyParameters();5$mock = Phake::mock('Hello');6Phake::when($mock)->say($anyParameters)->thenReturn('Hello World');

Full Screen

Full Screen

AnyParameters

Using AI Code Generation

copy

Full Screen

1include 'AnyParameters.php';2include 'Phake.php';3include 'PhakeCall.php';4include 'PhakeCallRecorder.php';5include 'PhakeCallVerifier.php';6include 'PhakeCallVerifierMode.php';7include 'PhakeClassGenerator.php';8include 'PhakeClassGeneratorException.php';9include 'PhakeClassGeneratorMode.php';10include 'PhakeClassGeneratorProxy.php';11include 'PhakeClassGeneratorProxyException.php';12include 'PhakeClassGeneratorProxyMode.php';13include 'PhakeException.php';14include 'PhakeMatchers.php';15include 'PhakeStubber.php';16include 'PhakeStubberException.php';17include 'PhakeStubberMode.php';18include 'PhakeStubberProxy.php';19include 'PhakeStubberProxyException.php';20include 'PhakeStubberProxyMode.php';21include 'PhakeStubberProxyReturn.php';22include 'PhakeStubberProxyReturnException.php';23include 'PhakeStubberProxyReturnMode.php';24include 'PhakeStubberProxyThrow.php';25include 'PhakeStubberProxyThrowException.php';26include 'PhakeStubberProxyThrowMode.php';

Full Screen

Full Screen

AnyParameters

Using AI Code Generation

copy

Full Screen

1{2 public function test1()3 {4 $mock = $this->getMock('SomeClass', array('getUniqueId'));5 $mock->expects($this->once())6 ->method('getUniqueId')7 ->with($this->equalTo(0));8 $mock->getUniqueId(1);9 }10}

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.

Run Phake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful