-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExecutionContextTest.php
More file actions
102 lines (84 loc) · 3.23 KB
/
ExecutionContextTest.php
File metadata and controls
102 lines (84 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace PhpSchool\PhpWorkshopTest\ExerciseRunner\Context;
use PhpSchool\PhpWorkshop\Exercise\MockExercise;
use PhpSchool\PhpWorkshop\ExerciseRunner\Context\ExecutionContext;
use PhpSchool\PhpWorkshop\ExerciseRunner\Context\NoEntryPoint;
use PhpSchool\PhpWorkshop\Input\Input;
use PhpSchool\PhpWorkshop\Utils\System;
use PHPUnit\Framework\TestCase;
class ExecutionContextTest extends TestCase
{
public function testGetters(): void
{
$exercise = new MockExercise();
$input = new Input('test', ['program' => 'solution.php']);
$context = new ExecutionContext(
'/student-dir',
'/reference-dir',
$exercise,
$input
);
static::assertSame($exercise, $context->getExercise());
static::assertSame($input, $context->getInput());
static::assertSame('/student-dir', $context->getStudentExecutionDirectory());
static::assertSame('/reference-dir', $context->getReferenceExecutionDirectory());
}
public function testHasStudentSolution(): void
{
$exercise = new MockExercise();
$input = new Input('test', ['program' => 'solution.php']);
$context = new ExecutionContext(
'/student-dir',
'/reference-dir',
$exercise,
$input
);
static::assertTrue($context->hasStudentSolution());
$exercise = new MockExercise();
$input = new Input('test');
$context = new ExecutionContext(
'/student-dir',
'/reference-dir',
$exercise,
$input
);
static::assertFalse($context->hasStudentSolution());
}
public function testGetEntryPoint(): void
{
$exercise = new MockExercise();
$input = new Input('test', ['program' => 'solution.php']);
$context = new ExecutionContext(
'/student-dir',
'/reference-dir',
$exercise,
$input
);
static::assertSame('/student-dir/solution.php', $context->getEntryPoint());
}
public function testGetEntryPointThrowsExceptionWhenNoStudentSolution(): void
{
static::expectException(NoEntryPoint::class);
$exercise = new MockExercise();
$input = new Input('test');
$context = new ExecutionContext(
'/student-dir',
'/reference-dir',
$exercise,
$input
);
$context->getEntryPoint();
}
public function testFactory(): void
{
$temporaryDirectory = System::randomTempDir();
$input = new Input('test', ['program' => $temporaryDirectory . '/solution.php']);
$exercise = new MockExercise();
$context = ExecutionContext::fromInputAndExercise($input, $exercise);
//check that student execution directory uses the parent directory of the program from the input
static::assertSame($temporaryDirectory, $context->getStudentExecutionDirectory());
static::assertSame($temporaryDirectory . '/solution.php', $context->getEntryPoint());
//check that reference execution directory is a random temporary directory
static::assertTrue(str_starts_with($context->getReferenceExecutionDirectory(), System::tempDir()));
}
}