public function testAlteringDatabaseInSolutionDoesNotEffectDatabaseInUserSolution() { $solution = SingleFileSolution::fromFile(realpath(__DIR__ . '/../res/database/solution-alter-db.php')); $this->exercise->expects($this->once())->method('getSolution')->will($this->returnValue($solution)); $this->exercise->expects($this->any())->method('getArgs')->will($this->returnValue([])); $this->exercise->expects($this->atLeastOnce())->method('getType')->will($this->returnValue(ExerciseType::CLI())); $this->exercise->expects($this->once())->method('configure')->will($this->returnCallback(function (ExerciseDispatcher $dispatcher) { $dispatcher->requireCheck(DatabaseCheck::class); })); $this->exercise->expects($this->once())->method('seed')->with($this->isInstanceOf(PDO::class))->will($this->returnCallback(function (PDO $db) { $db->exec('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER, gender TEXT)'); $stmt = $db->prepare('INSERT into users (name, age, gender) VALUES (:name, :age, :gender)'); $stmt->execute([':name' => 'Jimi Hendrix', ':age' => 27, ':gender' => 'Male']); })); $this->exercise->expects($this->once())->method('verify')->with($this->isInstanceOf(PDO::class))->will($this->returnCallback(function (PDO $db) { $users = $db->query('SELECT * FROM users'); $users = $users->fetchAll(PDO::FETCH_ASSOC); $this->assertEquals([['id' => 1, 'name' => 'Jimi Hendrix', 'age' => '27', 'gender' => 'Male'], ['id' => 2, 'name' => 'Kurt Cobain', 'age' => '27', 'gender' => 'Male']], $users); })); $results = new ResultAggregator(); $eventDispatcher = new EventDispatcher($results); $checkRepository = new CheckRepository([$this->check]); $dispatcher = new ExerciseDispatcher(new RunnerFactory(), $results, $eventDispatcher, $checkRepository); $dispatcher->verify($this->exercise, __DIR__ . '/../res/database/user-solution-alter-db.php'); }
public function testVerify() { $this->createExercise(); $this->exercise->expects($this->once())->method('configure')->with($this->exerciseDispatcher); $this->check->expects($this->once())->method('check')->will($this->returnValue(new Success('Success'))); $this->check->expects($this->once())->method('canRun')->with($this->exerciseType)->will($this->returnValue(true)); $this->check->expects($this->once())->method('getExerciseInterface')->will($this->returnValue(ExerciseInterface::class)); $this->mockRunner(); $this->runner->expects($this->once())->method('verify')->with($this->file)->will($this->returnValue($this->getMock(SuccessInterface::class))); $this->exerciseDispatcher->requireCheck(get_class($this->check), ExerciseDispatcher::CHECK_BEFORE); $result = $this->exerciseDispatcher->verify($this->exercise, $this->file); $this->assertInstanceOf(ResultAggregator::class, $result); $this->assertTrue($result->isSuccessful()); }