/**
  * @param array $data
  * @param array $expected
  * @dataProvider deserializerProvider
  */
 public function testDeserialize(array $data, array $expected)
 {
     mkdir($this->tmpDir, 0777, true);
     file_put_contents($this->tmpFile, json_encode($data));
     $serializer = new UserStateSerializer($this->tmpFile);
     $state = $serializer->deSerialize();
     $this->assertEquals($expected['completed_exercises'], $state->getCompletedExercises());
     $this->assertEquals($expected['current_exercise'], $state->getCurrentExercise());
     if (file_exists($this->tmpFile)) {
         unlink($this->tmpFile);
     }
     rmdir($this->tmpDir);
 }
 public function testOldDataWillNotBeMigratedWhenNotInCorrectWorkshopWithOtherWorkshop()
 {
     $oldSave = sprintf('%s/.phpschool.json', $this->tmpDir);
     $newSave = sprintf('%s/.phpschool-save.json', $this->tmpDir);
     $exercise1 = $this->prophesize(CliExerciseInterface::class);
     $exercise2 = $this->prophesize(CliExerciseInterface::class);
     $exercise1->getType()->willReturn(ExerciseType::CLI());
     $exercise2->getType()->willReturn(ExerciseType::CLI());
     $exercise1->getName()->willReturn('Exercise 1');
     $exercise2->getName()->willReturn('Exercise 2');
     $exercises = [$exercise1->reveal(), $exercise2->reveal()];
     $repo = new ExerciseRepository($exercises);
     $oldData = ['current_exercise' => 'Exercise 3', 'completed_exercises' => ['Exercise 1 from a diff workshop', 'Exercise 2 from a diff workshop']];
     $newData = ['My Workshop' => ['current_exercise' => 'Exercise 2', 'completed_exercises' => ['Exercise 1']]];
     mkdir($this->tmpDir, 0777, true);
     file_put_contents($oldSave, json_encode($oldData));
     file_put_contents($newSave, json_encode($newData));
     $serializer = new UserStateSerializer($this->tmpDir, $this->workshopName, $repo);
     $state = $serializer->deSerialize();
     $this->assertEquals(['Exercise 1'], $state->getCompletedExercises());
     $this->assertEquals('Exercise 2', $state->getCurrentExercise());
     $expected = ['current_exercise' => 'Exercise 3', 'completed_exercises' => ['Exercise 1 from a diff workshop', 'Exercise 2 from a diff workshop']];
     $this->assertFileExists($oldSave);
     $this->assertEquals($expected, json_decode(file_get_contents($oldSave), true));
     $this->assertFileExists($newSave);
     $this->assertEquals($newData, json_decode(file_get_contents($newSave), true));
     unlink($oldSave);
 }