Example #1
0
 public function testSemver()
 {
     $semver = test::double('Robo\\Task\\SemVerTask', ['dump' => null]);
     $res = $this->taskSemVer()->increment('major')->prerelease('RC')->increment('patch')->run();
     verify($res->getMessage())->equals('v1.0.1-RC.1');
     $semver->verifyInvoked('dump');
 }
Example #2
0
 /**
  * @test
  */
 public function it_should_fire_job_with_resolvable_models()
 {
     /**
      *
      * Set
      *
      */
     $app = m::mock('Illuminate\\Foundation\\Application');
     $config = m::mock('Menthol\\Flexible\\Config');
     $logger = m::mock('Monolog\\Logger');
     $model = m::mock('Husband');
     $model->shouldReceive('refreshDoc')->with($model)->once();
     $husband = am::double('Husband', ['findOrFail' => $model]);
     $models = ['Husband:999'];
     /**
      *
      * Expectation
      *
      */
     $logger->shouldReceive('info')->with('Indexing Husband with ID: 999');
     $config->shouldReceive('get')->with('logger', 'menthol.flexible.logger')->andReturn('menthol.flexible.logger');
     $app->shouldReceive('make')->with('menthol.flexible.logger')->andReturn($logger);
     $job = m::mock('Illuminate\\Queue\\Jobs\\Job');
     $job->shouldReceive('delete')->once();
     /**
      *
      * Assertion
      *
      */
     with(new ReindexJob($app, $config))->fire($job, $models);
     // $husband->verifyInvoked('findOrFail');
 }
 public function testCanSetSail()
 {
     $config = array('routes' => array('/' => array('controller' => 'index', 'action' => 'index', 'params' => array())));
     Test::double('\\Bone\\Mvc\\Request', ['getURI' => '/']);
     Test::double('\\Bone\\Mvc\\Dispatcher', ['fireCannons' => null]);
     $this->assertNull(Application::ahoy($config)->setSail());
 }
 public function testModelCall()
 {
     // This test demonstrates how to create a test double for Mage
     // Normally you would be testing a separate classes method so
     // some of the logic below would be in a separate file, obvs.
     // Using PhpUnits mock builder we can create a stub object for
     // a Magento core file. Which allows us to control what the
     // method calls return and also assert they are invoked, etc.
     $mockModel = $this->getMockBuilder('Mage_Catalog_Model_Product')->setMethods(array('getSku'))->getMock();
     $mockModel->expects($this->once())->method('getSku')->will($this->returnValue('123456789'));
     // Because getting a model in Magento consists of a static call
     // it makes testing difficult. To counter this we are using a
     // library called AspectMock which uses Go! AOP to allow us to
     // create test doubles for static method calls. WIN!
     $modelStub = test::double('Mage', ['getModel' => $mockModel]);
     // This is the logic we would be testing
     $model = Mage::getModel('catalog/product');
     $sku = $model->getSku();
     // Because our $modelStub returned our $mockModel when Mage::getModel()
     // is called $model is the same as our $mockModel. By calling getSku()
     // we are using the stubbed model method which returns our defined result.
     $this->assertSame('123456789', $sku);
     // We will also want to assert that the stubbed static method was
     // actually called.
     $modelStub->verifyInvokedOnce('getModel', 'catalog/product');
 }
 public function tearDown()
 {
     parent::tearDown();
     Mockery::close();
     Test::clean();
     $this->dropDatabase();
 }
Example #6
0
 protected function _before()
 {
     $progressBar = test::double('Symfony\\Component\\Console\\Helper\\ProgressBar');
     $nullOutput = new \Symfony\Component\Console\Output\NullOutput();
     $progressIndicator = new \Robo\Common\ProgressIndicator($progressBar, $nullOutput);
     $this->svn = test::double('Robo\\Task\\Vcs\\SvnStack', ['executeCommand' => new \AspectMock\Proxy\Anything(), 'output' => $nullOutput, 'logger' => new \Psr\Log\NullLogger(), 'logger' => Robo::logger(), 'getConfig' => Robo::config(), 'progressIndicator' => $progressIndicator]);
 }
Example #7
0
 /**
  *  Test shutting down the bitcoin server
  *  Fake client so it doesnt really shut down
  */
 public function testStop()
 {
     Test::double('Del\\Bitcoin\\Api\\AbstractApi', ['send' => null]);
     $this->api = new Control($this->config);
     $result = $this->api->stop();
     $this->assertNull($result);
 }
 /**
  * @test
  */
 public function it_should_fire_job_with_resolvable_models()
 {
     /**
      *
      * Set
      *
      */
     $model = m::mock('Husband');
     $model->shouldReceive('refreshDoc')->with($model)->once();
     $husband = am::double('Husband', ['findOrFail' => $model]);
     $models = ['Husband:999'];
     /**
      *
      * Expectation
      *
      */
     $job = m::mock('Illuminate\\Queue\\Jobs\\Job');
     $job->shouldReceive('delete')->once();
     /**
      *
      * Assertion
      *
      */
     with(new ReindexJob())->fire($job, $models);
     $husband->verifyInvoked('findOrFail');
 }
Example #9
0
 public function testGulpRun()
 {
     $gulp = test::double('Robo\\Task\\Gulp\\Run', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]);
     $task = (new \Robo\Task\Gulp\Run('default', 'gulp'))->simple();
     verify($task->getCommand())->equals($this->adjustQuotes('gulp "default" --tasks-simple'));
     $task->run();
     $gulp->verifyInvoked('executeCommand', [$this->adjustQuotes('gulp "default" --tasks-simple')]);
 }
Example #10
0
 public function testBowerUpdate()
 {
     $bower = test::double('Robo\\Task\\Bower\\Update', ['executeCommand' => null]);
     $task = new \Robo\Task\Bower\Update('bower');
     $task->setLogger(new \Psr\Log\NullLogger());
     $task->run();
     $bower->verifyInvoked('executeCommand', ['bower update']);
 }
Example #11
0
 public function testBehatCommand()
 {
     $behat = test::double('Robo\\Task\\Testing\\Behat', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]);
     $task = (new \Robo\Task\Testing\Behat('behat'))->stopOnFail()->noInteraction()->colors();
     verify($task->getCommand())->equals('behat run --stop-on-failure --no-interaction --colors');
     $task->run();
     $behat->verifyInvoked('executeCommand', ['behat run --stop-on-failure --no-interaction --colors']);
 }
 /**
  * @expectedException \Boedy\Subscription\SubscriptionErrorException
  */
 public function testUnsuccessfulUnsubscribe()
 {
     $parameters = array('client_id' => '123456789', 'client_secret' => 'abcdefghij');
     //return 400 response
     Test::double('\\Boedy\\Http\\Request\\Delete', ['exec' => new HttpResponse('header', 'body', 400)]);
     $factory = new HttpRequestFactory();
     $instagramAdapter = new InstagramAdapter($factory);
     $instagramAdapter->unsubscribe($parameters);
 }
Example #13
0
 public function testCantLoginWithoutPassword()
 {
     test::double('common\\models\\User', ['validatePassword' => true]);
     $model = new LoginForm();
     $model->username = '******';
     $this->assertFalse($model->login());
     $model->password = '******';
     $this->assertTrue($model->login());
 }
 public function testFailedVerification()
 {
     $this->setExpectedException('PHPUnit_Framework_ExpectationFailedException');
     $func = test::func('demo', 'strlen', function () {
         return 10;
     });
     expect(strlen('hello'))->equals(10);
     $func->verifyNeverInvoked('strlen');
 }
Example #15
0
 public function testCreateController()
 {
     Test::double('\\Twig_Loader_Filesystem');
     Test::double('\\Twig_Environment');
     Test::double('\\Twig_Extension_Debug');
     Test::double('\\Bone\\Mvc\\Controller', array('setTwig' => null));
     $factory = new ControllerFactory();
     $controller = $factory->create('\\Bone\\Mvc\\Controller', $this->request);
     $this->assertInstanceOf('\\Bone\\Mvc\\Controller', $controller);
 }
Example #16
0
 public function testUserCreate()
 {
     $userProxy = test::double('User', ['save' => function () {
         echo "MOCKED User->save() called\n";
     }]);
     $service = new UserService();
     $user = $service->createUserByName('Zachary');
     $this->assertEquals('Zachary', $user->getName());
     $userProxy->verifyInvoked('save');
 }
 public function testUpdateListHasNothingToUpdate()
 {
     $userStubs = [['id' => 1], ['id' => 2]];
     $localCollectionStub = Test::double('PullAutomaticallyGalleries\\Database\\Eloquent\\Collection', ['diffByKey' => &$localCollectionStub, 'isEmpty' => true])->make();
     $remoteCollectionStub = Test::double('PullAutomaticallyGalleries\\Support\\Collection', ['diffByKey' => &$remoteCollectionStub, 'isEmpty' => true])->make();
     Gallery::shouldReceive('getByUsers')->with([1, 2])->once()->andReturn($localCollectionStub)->getMock();
     RemoteGallery::shouldReceive('getByUsers')->with($userStubs)->once()->andReturn($remoteCollectionStub);
     $this->call('POST', 'galleries', ['users' => $userStubs]);
     $this->assertRedirectedTo('users');
     $this->assertSessionHas('message', 'Has been removed 0 galleries and created 0 galleries');
 }
 public function testConnectionStatusIsUpdatedWithFailureAfterConfigSave()
 {
     AspectMock\Test::double("Tinify\\Client", ["request" => function () {
         throw new Tinify\AccountException("help an error");
     }]);
     $this->configModel->setDataByPath(Model\Config::KEY_PATH, "my_new_key");
     $this->configModel->save();
     $label = $this->getObjectManager()->get("Magento\\Framework\\Data\\Form\\Element\\Label");
     $status = $this->getObjectManager()->get("Tinify\\Magento\\Model\\Config\\ConnectionStatusField");
     $this->assertEquals('<td class="value">' . '<div class="tinify-connection-status tinify-failure">' . '<div class="control-value">API connection unsuccessful.</div>' . '</div>' . '<p class="note"><span>Error: help an error</span></p>' . '</td>', $this->callMethod($status, "_renderValue", $label));
 }
 public function testMockingClassMethod()
 {
     $this->initAspectMock();
     //$mock = \AspectMock\Test::double(MyClass::class, ['myClassMethod' => 'a']);
     $mock = \AspectMock\Test::double('MyClass', ['myClassMethod' => 'a']);
     //$mock = \AspectMock\Test::double('\MyClass', ['myClassMethod' => 'a']);
     $classMethodReturned = MyClass::myClassMethod();
     // Extra verification to see if the AspectMock double is actually being run yet:
     //$mock->verifyInvoked('myClassMethod');
     $this->assertEquals('a', $classMethodReturned);
 }
Example #20
0
 public function _after(\Codeception\TestCase $test)
 {
     // Ensure that $stopOnFail global static is reset, as tests
     // that set it to true will force an exception, and therefor
     // will not have a chance to clean this up.
     \Robo\Result::$stopOnFail = false;
     \AspectMock\Test::clean();
     $consoleOutput = new ConsoleOutput();
     static::$container->add('output', $consoleOutput);
     static::$container->add('logger', new \Consolidation\Log\Logger($consoleOutput));
 }
Example #21
0
 public function testSemverIncrementMajorAfterIncrementedMinorAndPatch()
 {
     $semver = test::double('Robo\\Task\\Development\\SemVer', ['dump' => null]);
     $res = (new \Robo\Task\Development\SemVer())->increment('patch')->run();
     verify($res->getMessage())->equals('v0.0.1');
     $res = (new \Robo\Task\Development\SemVer())->increment('minor')->run();
     verify($res->getMessage())->equals('v0.1.0');
     $res = (new \Robo\Task\Development\SemVer())->increment('major')->run();
     verify($res->getMessage())->equals('v1.0.0');
     $semver->verifyInvoked('dump');
 }
Example #22
0
 public function testComposerDumpAutoload()
 {
     $composer = test::double('Robo\\Task\\Composer\\DumpAutoload', ['executeCommand' => null]);
     $this->taskComposerDumpAutoload('composer')->run();
     $composer->verifyInvoked('executeCommand', ['composer dump-autoload']);
     $this->taskComposerDumpAutoload('composer')->noDev()->run();
     $composer->verifyInvoked('executeCommand', ['composer dump-autoload --no-dev']);
     $this->taskComposerDumpAutoload('composer')->optimize()->run();
     $composer->verifyInvoked('executeCommand', ['composer dump-autoload --optimize']);
     $this->taskComposerDumpAutoload('composer')->optimize()->noDev()->run();
     $composer->verifyInvoked('executeCommand', ['composer dump-autoload --optimize --no-dev']);
 }
 public function testReturnCorrectAttributeData()
 {
     $stub = Mockery::mock('PullAutomaticallyGalleries\\RemoteApi\\RemoteApiModelInterface')->shouldReceive('connect')->with('')->andReturn($this->userStub)->getMock();
     Test::double('RemoteUser', ['newModel' => $stub]);
     $user = RemoteUser::connect('DummyHost', '');
     assertThat($user->id, containsString('dummyhost_1'));
     assertThat($user->realname, is(equalTo($this->userStub['realname'])));
     assertThat($user->username, is(equalTo($this->userStub['username'])));
     assertThat($user->url, is(equalTo($this->userStub['url'])));
     assertThat($user->credentials, is(equalTo($this->userStub['credentials'])));
     assertThat($user->host, is(equalTo('DummyHost')));
 }
 public function testIndexRenderCalledContent()
 {
     $target = test::double('SiteController', ['render' => function ($viewName) {
         echo "Content for {$viewName}";
     }]);
     ob_start();
     $controller = $this->getNewSiteController();
     $controller->actionIndex();
     $output = ob_get_clean();
     $this->assertEquals('Content for index', $output);
     $target->verifyInvoked('render');
 }
Example #25
0
 public function testCall()
 {
     $request = $this->prepareRequest();
     // check if curl is not installed
     test::func('esia', 'curl_init', false);
     $response = $request->call('stub');
     $this->assertNull($response);
     // check if correct call
     test::clean();
     test::func('esia', 'curl_exec', '{}');
     $response = $request->call('stub');
     $this->assertTrue($response instanceof \stdClass);
 }
 public function testModuleInit()
 {
     $this->vfsRoot->addChild($this->createFile('file1'));
     $this->vfsRoot->addChild($this->createFile('file1'));
     $this->vfsRoot->addChild(vfsStream::newDirectory('dir1'));
     AspectMock::double(\Codeception\Configuration::class, ['outputDir' => vfsStream::url('outputDir')]);
     // Cleansman needs no configuration atm
     $event = m::mock(\Codeception\Event\SuiteEvent::class);
     $sut = new \Codeception\Extension\Cleansman([], ['silent' => false]);
     // Actual cleanup happens here
     $sut->moduleInit($event);
     $this->assertFalse($this->vfsRoot->hasChild('file1'));
     $this->assertFalse($this->vfsRoot->hasChild('file2'));
     $this->assertFalse($this->vfsRoot->hasChild('dir1'));
 }
Example #27
0
 public function testComposerValidate()
 {
     $composer = test::double('Robo\\Task\\Composer\\Validate', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]);
     (new \Robo\Task\Composer\Validate('composer'))->run();
     $composer->verifyInvoked('executeCommand', ['composer validate']);
     (new \Robo\Task\Composer\Validate('composer'))->noCheckAll()->run();
     $composer->verifyInvoked('executeCommand', ['composer validate --no-check-all']);
     (new \Robo\Task\Composer\Validate('composer'))->noCheckLock()->run();
     $composer->verifyInvoked('executeCommand', ['composer validate --no-check-lock']);
     (new \Robo\Task\Composer\Validate('composer'))->noCheckPublish()->run();
     $composer->verifyInvoked('executeCommand', ['composer validate --no-check-publish']);
     (new \Robo\Task\Composer\Validate('composer'))->withDependencies()->run();
     $composer->verifyInvoked('executeCommand', ['composer validate --with-dependencies']);
     (new \Robo\Task\Composer\Validate('composer'))->strict()->run();
     $composer->verifyInvoked('executeCommand', ['composer validate --strict']);
 }
Example #28
0
 public function testClassWithTraits()
 {
     // if a trait is used by more than one doubled class, when BeforeMockTransformer
     // runs on the second class it will see the trait's methods as being a part of
     // the class itself, and try to inject its code into the class, rather than the
     // trait. in failure mode, this test will result in:
     // Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION)
     // in [...]/TraitedModel2.php
     $unused = test::double('demo\\TraitedClass1');
     // this model uses `TraitedModelTrait`
     $class = test::double('demo\\TraitedClass2');
     // so does this one
     /** @var $class ClassProxy **/
     verify($class->isDefined())->true();
     verify($class->hasMethod('method1InTrait'))->true();
     verify($class->hasMethod('methodInClass'))->true();
 }
Example #29
0
 /**
  * @test
  */
 public function it_should_not_reindex_on_model_save()
 {
     /**
      *
      * Expectation
      *
      */
     $queue = am::double('Illuminate\\Support\\Facades\\Queue', ['push' => null]);
     $husband = m::mock('Husband');
     $husband->shouldReceive('shouldIndex')->andReturn(false);
     /**
      *
      * Assertion
      *
      */
     with(new Observer())->saved($husband);
     $queue->verifyNeverInvoked('push');
 }
Example #30
0
 /**
  * @test
  */
 public function it_should_fire_job()
 {
     /**
      *
      * Set
      *
      */
     $husband = am::double('Husband', ['deleteDoc' => true]);
     $job = m::mock('Illuminate\\Queue\\Jobs\\Job');
     $models = ['Husband:999'];
     /**
      *
      * Expectation
      *
      */
     $job->shouldReceive('delete')->once();
     /**
      *
      * Assertion
      *
      */
     with(new DeleteJob())->fire($job, $models);
 }