Skip to content

Commit

Permalink
added 'remove' command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashur committed Aug 12, 2017
1 parent 5bff08e commit 96bc29b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/commands/PugTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ public function usePugfile( $filename )
{
$dirPugfiles = self::$fixturesPath . '/pugfiles';

self::$pugfilePath = self::$fixturesPath . '/.pug-' . microtime( true );

$sourceFilename = "{$dirPugfiles}/{$filename}";
$targetFilename = self::$pugfilePath;

if( file_exists( $sourceFilename ) )
{
copy( $sourceFilename, $targetFilename );
$this->assertEquals( file_get_contents( $sourceFilename ), file_get_contents( $targetFilename ) );
}
else
{
Expand Down
81 changes: 81 additions & 0 deletions test/commands/removeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/*
* This file is part of Pug
*/

include_once( 'PugTestCase.php' );

use PHPUnit\Framework\TestCase;

class removeTest extends PugTestCase
{
public function testRemoveEmptyQueryDisplaysUsage()
{
$result = $this->executePugCommand( 'remove' );

$this->assertEquals( 1, $result['exit'] );

$expectedOutput = <<<OUTPUT
usage: pug rm [all|<group>[/<project>]|<project>] [-y|--yes|--assume-yes]
OPTIONS
-y, --yes, --assume-yes
Automatic yes to prompts. Assume "yes" as answer to all prompts and run
non-interactively.
OUTPUT;

$this->assertEquals( $expectedOutput, $result['output'] );
}

public function testRemoveAllReturnsNoOutput()
{
$this->usePugfile( '.pug-enabled' );
$result = $this->executePugCommand( 'remove', ['all', '--yes'] );

$this->assertEquals( 0, $result['exit'] );
$this->assertEquals( '', $result['output'] );
}

public function testRemoveGroupReturnsListing()
{
$this->usePugfile( '.pug-groups' );
$result = $this->executePugCommand( 'remove', ['green', '--yes'] );

$this->assertEquals( 0, $result['exit'] );

$expectedOutput = <<<OUTPUT
* red/1
* red/2
OUTPUT;

$this->assertEquals( $expectedOutput, $result['output'] );
}

public function testRemoveProjectReturnsListing()
{
$this->usePugfile( '.pug-groups' );
$result = $this->executePugCommand( 'remove', ['red/1'] );

$this->assertEquals( 0, $result['exit'] );

$expectedOutput = <<<OUTPUT
* green/1
* red/2
OUTPUT;

$this->assertEquals( $expectedOutput, $result['output'] );
}

public function testRemoveNonExistentTargetReturnsError()
{
$this->usePugfile( '.pug-groups' );

$targetName = microtime( true );
$result = $this->executePugCommand( 'remove', [$targetName] );

$this->assertEquals( 1, $result['exit'] );
$this->assertEquals( "pug: No groups or projects match '{$targetName}'.", $result['output'] );
}
}
22 changes: 22 additions & 0 deletions test/fixtures/pugfiles/.pug-groups
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"projects": [
{
"name": "red/1",
"path": "./",
"enabled": true,
"updated": 1502560725
},
{
"name": "green/1",
"path": "./",
"enabled": true,
"updated": 1502560725
},
{
"name": "red/2",
"path": "./",
"enabled": true,
"updated": 1502560725
}
]
}

0 comments on commit 96bc29b

Please sign in to comment.