Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic unit tests #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"src/Deployer/functions.php"
]
},
"autoload-dev": {
"psr-4": {
"Hypernode\\Deploy\\": "tests/unit"
}
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"roave/security-advisories": "dev-master"
Expand Down
10 changes: 10 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
verbose="false">
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/unit</directory>
</testsuite>
</testsuites>
</phpunit>
52 changes: 52 additions & 0 deletions tests/unit/Command/BuildTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Hypernode\Deploy\Command;

use Hypernode\Deploy\DeployRunner;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class BuildTest extends TestCase
{
/**
* @var DeployRunner|MockObject
*/
private $deployRunner;
/**
* @var InputInterface|MockObject
*/
private $input;
/**
* @var OutputInterface|MockObject
*/
private $output;

/**
* @var Build
*/
private $command;

protected function setUp(): void
{
$this->deployRunner = $this->createMock(DeployRunner::class);
$this->input = $this->createMock(InputInterface::class);
$this->output = $this->createMock(OutputInterface::class);
$this->command = new Build($this->deployRunner);
}

public function test_it_calls_deploy_runner_correctly()
{
$this->deployRunner->expects($this->once())
->method('run')
->with($this->output, 'build', 'build');

$this->command->run($this->input, $this->output);
}

public function test_it_returns_zero()
{
$this->assertEquals(0, $this->command->run($this->input, $this->output));
}
}
52 changes: 52 additions & 0 deletions tests/unit/Command/ComposerAuthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Hypernode\Deploy\Command;

use Hypernode\Deploy\DeployRunner;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ComposerAuthTest extends TestCase
{
/**
* @var DeployRunner|MockObject
*/
private $deployRunner;
/**
* @var InputInterface|MockObject
*/
private $input;
/**
* @var OutputInterface|MockObject
*/
private $output;

/**
* @var Build
*/
private $command;

protected function setUp(): void
{
$this->deployRunner = $this->createMock(DeployRunner::class);
$this->input = $this->createMock(InputInterface::class);
$this->output = $this->createMock(OutputInterface::class);
$this->command = new ComposerAuth($this->deployRunner);
}

public function test_it_calls_deploy_runner_correctly()
{
$this->deployRunner->expects($this->once())
->method('run')
->with($this->output, 'build', 'deploy:vendors:auth');

$this->command->run($this->input, $this->output);
}

public function test_it_returns_zero()
{
$this->assertEquals(0, $this->command->run($this->input, $this->output));
}
}
60 changes: 60 additions & 0 deletions tests/unit/Command/DeployTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Hypernode\Deploy\Command;

use Hypernode\Deploy\DeployRunner;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class DeployTest extends TestCase
{
/**
* @var DeployRunner|MockObject
*/
private $deployRunner;
/**
* @var InputInterface|MockObject
*/
private $input;
/**
* @var OutputInterface|MockObject
*/
private $output;

/**
* @var Build
*/
private $command;

protected function setUp(): void
{
$this->deployRunner = $this->createMock(DeployRunner::class);
$this->input = $this->createMock(InputInterface::class);
$this->output = $this->createMock(OutputInterface::class);
$this->command = new Deploy($this->deployRunner);
}

protected function assertPreConditions(): void
{
$this->input->expects($this->once())
->method('getArgument')
->with('stage')
->willReturn('production');
}

public function test_it_calls_deploy_runner_correctly()
{
$this->deployRunner->expects($this->once())
->method('run')
->with($this->output, 'production', 'deploy');

$this->command->run($this->input, $this->output);
}

public function test_it_returns_zero()
{
$this->assertEquals(0, $this->command->run($this->input, $this->output));
}
}
60 changes: 60 additions & 0 deletions tests/unit/Command/RunTaskTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Hypernode\Deploy\Command;

use Hypernode\Deploy\DeployRunner;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RunTaskTest extends TestCase
{
/**
* @var DeployRunner|MockObject
*/
private $deployRunner;
/**
* @var InputInterface|MockObject
*/
private $input;
/**
* @var OutputInterface|MockObject
*/
private $output;

/**
* @var Build
*/
private $command;

protected function setUp(): void
{
$this->deployRunner = $this->createMock(DeployRunner::class);
$this->input = $this->createMock(InputInterface::class);
$this->output = $this->createMock(OutputInterface::class);
$this->command = new RunTask($this->deployRunner);
}

protected function assertPreConditions(): void
{
$this->input->expects($this->exactly(2))
->method('getArgument')
->withConsecutive(['stage'], ['task'])
->willReturnOnConsecutiveCalls('production', 'sample_task');
}

public function test_it_calls_deploy_runner_correctly()
{
$this->deployRunner->expects($this->once())
->method('run')
->with($this->output, 'production', 'sample_task');

$this->command->run($this->input, $this->output);
}

public function test_it_returns_zero()
{
$this->assertEquals(0, $this->command->run($this->input, $this->output));
}
}