public function testconnect() { $table = "test"; DB::shouldReceive('table')->once()->andReturn(Mockery::mock(['insert' => true])); $result = $this->database->connect($table); $this->assertInstanceOf('Sharad\\Systeminfo\\SqlDatabase', $result); }
/** * @test **/ public function canStartForeignKeysCheckIfSupported() { $mock_exec = m::mock('StdClass')->shouldReceive('exec')->once()->with('SET FOREIGN_KEY_CHECKS=1;')->getMock(); $mock_getPdo = m::mock('StdClass')->shouldReceive('getPdo')->once()->andReturn($mock_exec)->getMock(); DB::shouldReceive('connection')->once()->andReturn($mock_getPdo); DbHelperStub::startForeignKeysCheck(); }
public function testMakeAssembly() { $item = $this->newInventory(); DB::shouldReceive('beginTransaction')->once()->andReturn(true); DB::shouldReceive('commit')->once()->andReturn(true); Event::shouldReceive('fire')->once()->andReturn(true); $item->makeAssembly(); $this->assertTrue($item->is_assembly); }
public function testStockMove() { $stock = $this->newInventoryStock(); $newLocation = Location::create(['name' => 'New Location']); DB::shouldReceive('beginTransaction')->once()->shouldReceive('commit')->once(); Event::shouldReceive('fire')->once(); $stock->moveTo($newLocation); $this->assertEquals(2, $stock->location_id); }
public function testUpdateCache() { $comment = new Comment(); $comment->post_id = 1; $comment->syncOriginal(); $comment->post_id = 2; DB::shouldReceive('update')->with('UPDATE `posts` SET `num_comments` = `num_comments` - 1 WHERE `id` = 1')->once(); DB::shouldReceive('update')->with('UPDATE `posts` SET `num_comments` = `num_comments` + 1 WHERE `id` = 2')->once(); $this->manager->updateCache($comment); }
public function testInventoryTransactionCheckout() { $transaction = $this->newTransaction(); DB::shouldReceive('startTransaction')->once(); DB::shouldReceive('commit')->once(); $transaction->checkout(5, 'Checking out', 25); $this->assertEquals(5, $transaction->quantity); $this->assertEquals(InventoryTransaction::STATE_COMMERCE_CHECKOUT, $transaction->state); $stock = $transaction->getStockRecord(); $this->assertEquals('Checking out', $stock->reason); $this->assertEquals(25, $stock->cost); }
public function testHandleCommits() { $subject = new Middleware(); $parameter = 'request'; $response = 'magic beans'; $callback = function ($request) use($parameter, $response) { expect($request)->equals($parameter); return $response; }; DB::shouldReceive('beginTransaction')->withNoArgs()->once(); EventStore::shouldReceive('publishQueue')->withNoArgs()->once(); DB::shouldReceive('rollBack')->withNoArgs()->never(); DB::shouldReceive('commit')->withNoArgs()->once(); expect($subject->handle('request', $callback))->equals($response); }
public function testDown() { $queryBuilder = m::mock('Illuminate\\Database\\Query\\Builder'); $queryBuilder->shouldReceive('truncate')->times(4); DB::shouldReceive('getDriverName')->andReturn('mysql'); DB::shouldReceive('statement')->with('SET FOREIGN_KEY_CHECKS=0;')->once(); DB::shouldReceive('statement')->with('SET FOREIGN_KEY_CHECKS=1;')->once(); DB::shouldReceive('table')->with('cities')->once()->andReturn($queryBuilder); DB::shouldReceive('table')->with('users')->once()->andReturn($queryBuilder); DB::shouldReceive('table')->with('countries')->once()->andReturn($queryBuilder); DB::shouldReceive('table')->with('logs')->once()->andReturn($queryBuilder); $fixtures = new \Mayconbordin\L5Fixtures\Fixtures(['location' => __DIR__ . '/_data']); $fixtures->down(); $this->assertEquals(4, sizeof($fixtures->getFixtures())); }
public function testGetTotalVariantStock() { $this->newCategory(); $this->newMetric(); $coke = Inventory::create(['name' => 'Coke', 'description' => 'Delicious Pop', 'metric_id' => 1, 'category_id' => 1]); $cherryCoke = $coke->createVariant('Cherry Coke'); $cherryCoke->makeVariantOf($coke); $vanillaCherryCoke = $cherryCoke->createVariant('Vanilla Cherry Coke'); $vanillaCherryCoke->makeVariantOf($cherryCoke); DB::shouldReceive('beginTransaction')->once()->andReturn(true); DB::shouldReceive('commit')->once()->andReturn(true); Event::shouldReceive('fire')->once()->andReturn(true); $location = $this->newLocation(); // Allow duplicate movements configuration option Config::shouldReceive('get')->twice()->andReturn(true); // Stock change reasons (one for create, one for put, for both items) Lang::shouldReceive('get')->times(4)->andReturn('Default Reason'); $cherryCoke->createStockOnLocation(20, $location); $vanillaCherryCoke->createStockOnLocation(20, $location); $this->assertEquals(40, $coke->getTotalVariantStock()); }
public function testFire() { DB::shouldReceive('statement')->once()->andReturn('foo'); $cmd = $this->getMockBuilder('Andizzle\\Zapper\\Console\\MigrateCommand')->disableOriginalConstructor()->getMock(); $cmd->fire(); }
function it_can_return_computed_column_type_info() { Cache::shouldReceive('has')->withAnyArgs()->once()->andReturn(false); Cache::shouldReceive('put')->withAnyArgs()->once(); $type = \Mockery::mock('Doctrine\\DBAL\\Types\\Type'); $type->shouldReceive('getName')->andReturn('Type'); $column = \Mockery::mock('Doctrine\\DBAL\\Schema\\Column'); $column->shouldReceive('getName')->andReturn('Column'); $column->shouldReceive('getType')->andReturn($type); $table = \Mockery::mock('Doctrine\\DBAL\\Schema\\Table'); $table->shouldReceive('getName')->andReturn('Table'); $table->shouldReceive('getColumn')->withAnyArgs()->andReturn($column); $schemaManager = \Mockery::mock('Doctrine\\DBAL\\Schema\\AbstractSchemaManager'); DB::shouldReceive('getDoctrineSchemaManager')->once()->andReturn($schemaManager); $schemaManager->shouldReceive('listTables')->once()->andReturn(['Table' => $table]); $this->getColumnType('Table', 'Column')->shouldBe('Type'); \Mockery::close(); }
/** * @test * @depends it_runs_the_main_process_steps_in_a_database_transaction */ function it_does_a_rollback_for_main_process_steps_if_an_exception_is_thrown() { DB::shouldReceive('beginTransaction')->once(); DB::shouldReceive('rollBack')->once(); $processor = new TestPipelineProcessor([], null, self::EXCEPTION_IN_MAIN_STEP); /** @var DataObjectInterface $data */ $data = $this->getMockBuilder(DataObjectInterface::class)->getMock(); try { $processor->process($data); } catch (\Exception $e) { // caught only to let test pass and check rollBack } }
public function testExists() { DB::shouldReceive('table')->with('test')->andReturnSelf(); DB::shouldReceive('where')->with('id', 1)->andReturnSelf(); DB::shouldReceive('first')->andReturn($this->model); $this->model->shouldReceive('getTable')->once()->andReturn('test'); $this->model->shouldReceive('getKeyName')->once()->andReturn('id'); $result = $this->repository->exists(1); $this->assertTrue($result); }
public function test_insert() { DB::shouldReceive('table->insert')->once(); $repository = new DatabaseExceptionRepository(); $repository->insert($attributes = ['user_id' => 9, 'critical' => true, 'class' => 'LogicNotFoundException', 'message' => 'This is a logic exception!', 'file' => 'AbstractFactory.php', 'line' => 100, 'trace' => 'trace', 'url' => 'https://watermark.local/asdasd', 'ip' => '24.57.183.293', 'user_agent' => 'user agent string here']); }
public function testDatabaseNeedsInstallFalse() { DB::shouldReceive('connection')->once()->andReturnSelf()->shouldReceive('getDatabaseName')->once()->andReturn('a_database_name'); $this->assertFalse($this->installer->databaseNeedsInstall()); }