/
CustomCommandRunnerTest.php
71 lines (64 loc) · 2.29 KB
/
CustomCommandRunnerTest.php
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
<?php
namespace Tienvx\Bundle\MbtBundle\Tests\Command\Runner;
use Facebook\WebDriver\Remote\LocalFileDetector;
use Facebook\WebDriver\Remote\RemoteWebElement;
use Facebook\WebDriver\WebDriverBy;
use Tienvx\Bundle\MbtBundle\Command\CommandRunner;
use Tienvx\Bundle\MbtBundle\Command\Runner\CustomCommandRunner;
use Tienvx\Bundle\MbtBundle\ValueObject\Model\Command;
/**
* @covers \Tienvx\Bundle\MbtBundle\Command\Runner\CustomCommandRunner
* @covers \Tienvx\Bundle\MbtBundle\Command\CommandRunner
*
* @uses \Tienvx\Bundle\MbtBundle\Model\Model\Revision\Command
*/
class CustomCommandRunnerTest extends RunnerTestCase
{
protected function createRunner(): CommandRunner
{
return new CustomCommandRunner('/path/to/upload-directory');
}
public function testUpload(): void
{
$command = new Command();
$command->setCommand(CustomCommandRunner::UPLOAD);
$command->setTarget('id=file_input');
$command->setValue('sub-directory/file.txt');
$element = $this->createMock(RemoteWebElement::class);
$element
->expects($this->once())
->method('setFileDetector')
->with($this->isInstanceOf(LocalFileDetector::class))
->willReturnSelf();
$element
->expects($this->once())
->method('sendKeys')
->with('/path/to/upload-directory/sub-directory/file.txt');
$this->driver->expects($this->once())->method('findElement')->with($this->callback(function ($selector) {
return $selector instanceof WebDriverBy
&& 'id' === $selector->getMechanism()
&& 'file_input' === $selector->getValue();
}))->willReturn($element);
$this->runner->run($command, $this->values, $this->driver);
}
public function targetProvider(): array
{
return [
[CustomCommandRunner::UPLOAD, null, false],
[CustomCommandRunner::UPLOAD, 'anything', false],
[CustomCommandRunner::UPLOAD, 'xpath=//path/to/element', true],
];
}
public function commandsRequireTarget(): array
{
return [
CustomCommandRunner::UPLOAD,
];
}
public function commandsRequireValue(): array
{
return [
CustomCommandRunner::UPLOAD,
];
}
}