Skip to content

Commit ecfed08

Browse files
committed
Fix tests for L5.0
1 parent ce8874e commit ecfed08

File tree

10 files changed

+59
-101
lines changed

10 files changed

+59
-101
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.lock
44
.DS_Store
55
.idea
66
coverage
7+
/tmp*

_ide_helper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,15 @@ public static function boot(){
952952
public static function call($command, $parameters = array(), $output = null){
953953
\Illuminate\Console\Application::call($command, $parameters, $output);
954954
}
955-
955+
956+
/**
957+
* @return string
958+
* @static
959+
*/
960+
public static function output(){
961+
return '';
962+
}
963+
956964
/**
957965
* Add a command to the console.
958966
*

src/Potsky/LaravelLocalizationHelpers/Factory/Localization.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Localization
99
const NO_LANG_FOLDER_FOUND_IN_THESE_PATHS = 2;
1010
const NO_LANG_FOLDER_FOUND_IN_YOUR_CUSTOM_PATH = 3;
1111
const BACKUP_DATE_FORMAT = "Ymd_His";
12-
const PREFIX_LARAVEL_CONFIG = 'laravel-localization-helpers::config.';
12+
const PREFIX_LARAVEL_CONFIG = 'laravel-localization-helpers.';
1313

1414
private static $PHP_CS_FIXER_LEVELS = array( 'psr0' , 'psr1' , 'psr2' , 'symfony' );
1515
private static $PHP_CS_FIXER_FIXERS = array(

tests/CommandClearTests.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use Potsky\LaravelLocalizationHelpers\Factory\Localization;
44
use Potsky\LaravelLocalizationHelpers\Factory\MessageBag;
5-
use Symfony\Component\Console\Output\BufferedOutput;
65

76
class CommandClearTests extends TestCase
87
{
@@ -37,10 +36,8 @@ public function setUp()
3736
*/
3837
public function testCleanAll()
3938
{
40-
$output = new BufferedOutput;
41-
4239
/** @noinspection PhpVoidFunctionResultUsedInspection */
43-
$return = Artisan::call( 'localization:clear' , array() , $output );
40+
$return = Artisan::call( 'localization:clear' , array() );
4441

4542
$this->assertEquals( 0 , $return );
4643
$this->assertCount( 0 , glob( self::LANG_DIR_PATH . '/*/message*.php' ) );
@@ -51,10 +48,8 @@ public function testCleanAll()
5148
*/
5249
public function testClean30Days()
5350
{
54-
$output = new BufferedOutput;
55-
5651
/** @noinspection PhpVoidFunctionResultUsedInspection */
57-
$return = Artisan::call( 'localization:clear' , array( '--days' => 30 ) , $output );
52+
$return = Artisan::call( 'localization:clear' , array( '--days' => 30 ) );
5853

5954
$this->assertEquals( 0 , $return );
6055
$this->assertCount( 20 , glob( self::LANG_DIR_PATH . '/*/message*.php' ) );
@@ -65,10 +60,8 @@ public function testClean30Days()
6560
*/
6661
public function testClean3Days()
6762
{
68-
$output = new BufferedOutput;
69-
7063
/** @noinspection PhpVoidFunctionResultUsedInspection */
71-
$return = Artisan::call( 'localization:clear' , array( '--days' => 3 ) , $output );
64+
$return = Artisan::call( 'localization:clear' , array( '--days' => 3 ) );
7265

7366
$this->assertEquals( 0 , $return );
7467
$this->assertCount( 6 , glob( self::LANG_DIR_PATH . '/*/message*.php' ) );
@@ -79,10 +72,8 @@ public function testClean3Days()
7972
*/
8073
public function testErrorDaysNegative()
8174
{
82-
$output = new BufferedOutput;
83-
8475
/** @noinspection PhpVoidFunctionResultUsedInspection */
85-
$return = Artisan::call( 'localization:clear' , array( '--days' => -3 ) , $output );
76+
$return = Artisan::call( 'localization:clear' , array( '--days' => -3 ) );
8677
$this->assertEquals( 1 , $return );
8778

8879
$manager = new Localization( new MessageBag() );
@@ -94,10 +85,8 @@ public function testErrorDaysNegative()
9485
*/
9586
public function testDryRun()
9687
{
97-
$output = new BufferedOutput;
98-
9988
/** @noinspection PhpVoidFunctionResultUsedInspection */
100-
$return = Artisan::call( 'localization:clear' , array( '--dry-run' => true ) , $output );
89+
$return = Artisan::call( 'localization:clear' , array( '--dry-run' => true ) );
10190

10291
$this->assertEquals( 0 , $return );
10392
$this->assertCount( 20 , glob( self::LANG_DIR_PATH . '/*/message*.php' ) );
@@ -111,29 +100,26 @@ public function testLangFolderDoesNotExist()
111100
{
112101
Config::set( Localization::PREFIX_LARAVEL_CONFIG . 'lang_folder_path' , self::LANG_DIR_PATH . 'doesnotexist' );
113102

114-
$output = new BufferedOutput;
115-
116103
/** @noinspection PhpVoidFunctionResultUsedInspection */
117-
$return = Artisan::call( 'localization:clear' , array( '--dry-run' => true ) , $output );
104+
$return = Artisan::call( 'localization:clear' , array( '--dry-run' => true ) );
118105

119106
$this->assertEquals( 1 , $return );
120-
$this->assertContains( 'No lang folder found in your custom path:' , $output->fetch() );
107+
$this->assertContains( 'No lang folder found in your custom path:' , Artisan::output() );
121108
}
122109

123110
/**
124111
* - Default lang folders are used when custom land folder path as not been set by user
112+
*
113+
* In Laravel 5.x, orchestra/testbench has not empty lang en directory, so return code is 0 and not 1
125114
*/
126115
public function testDefaultLangFolderDoesNotExist()
127116
{
128117
Config::set( Localization::PREFIX_LARAVEL_CONFIG . 'lang_folder_path' , null );
129118

130-
$output = new BufferedOutput;
131-
132119
/** @noinspection PhpVoidFunctionResultUsedInspection */
133-
$return = Artisan::call( 'localization:clear' , array( '--dry-run' => true ) , $output );
120+
$return = Artisan::call( 'localization:clear' , array( '--dry-run' => true ) );
134121

135-
$this->assertEquals( 1 , $return );
136-
$this->assertContains( 'No lang folder found in these paths:' , $output->fetch() );
122+
$this->assertEquals( 0 , $return );
137123
}
138124

139125
}

tests/CommandFindTests.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use Potsky\LaravelLocalizationHelpers\Factory\Localization;
44
use Potsky\LaravelLocalizationHelpers\Factory\MessageBag;
5-
use Symfony\Component\Console\Output\BufferedOutput;
65

76
class CommandFindTests extends TestCase
87
{
@@ -23,36 +22,29 @@ public function setUp()
2322
*/
2423
public function testSearchForRegularLemma()
2524
{
26-
$output = new BufferedOutput;
27-
2825
/** @noinspection PhpVoidFunctionResultUsedInspection */
29-
$return = Artisan::call( 'localization:find' , array( 'lemma' => 'message.lemma' , '--verbose' => true , '--short' => true ) , $output );
30-
$result = $output->fetch();
26+
$return = Artisan::call( 'localization:find' , array( 'lemma' => 'message.lemma' , '--verbose' => true , '--short' => true ) );
3127

3228
$this->assertEquals( 0 , $return );
33-
$this->assertContains( 'Lemma message.lemma has been found in' , $result );
29+
$this->assertContains( 'Lemma message.lemma has been found in' , Artisan::output() );
3430
}
3531

3632
/**
3733
*
3834
*/
3935
public function testSearchForRegexLemma()
4036
{
41-
$output = new BufferedOutput;
42-
4337
/** @noinspection PhpVoidFunctionResultUsedInspection */
44-
$return = Artisan::call( 'localization:find' , array( 'lemma' => 'message\\.lemma.*' , '--verbose' => true , '--short' => true , '--regex' => true ) , $output );
45-
$result = $output->fetch();
38+
$return = Artisan::call( 'localization:find' , array( 'lemma' => 'message\\.lemma.*' , '--verbose' => true , '--short' => true , '--regex' => true ) );
4639

4740
$this->assertEquals( 1 , $return );
48-
$this->assertContains( 'The argument is not a valid regular expression:' , $result );
41+
$this->assertContains( 'The argument is not a valid regular expression:' , Artisan::output() );
4942

5043
/** @noinspection PhpVoidFunctionResultUsedInspection */
51-
$return = Artisan::call( 'localization:find' , array( 'lemma' => '@message\\.lemma.*@' , '--verbose' => true , '--short' => true , '--regex' => true ) , $output );
52-
$result = $output->fetch();
44+
$return = Artisan::call( 'localization:find' , array( 'lemma' => '@message\\.lemma.*@' , '--verbose' => true , '--short' => true , '--regex' => true ) );
5345

5446
$this->assertEquals( 0 , $return );
55-
$this->assertContains( 'has been found in' , $result );
47+
$this->assertContains( 'has been found in' , Artisan::output() );
5648

5749
$messageBag = new MessageBag();
5850
$manager = new Localization( $messageBag );
@@ -86,9 +78,9 @@ public function testSearchForRegexLemma()
8678
) ,
8779
);
8880

89-
$return = $manager->findLemma( 'not a valid regex' , $manager->getPath( self::MOCK_DIR_PATH ) , $trans_methods , true , true );
81+
$return = $manager->findLemma( 'not a valid regex' , $manager->getPath( self::MOCK_DIR_PATH ) , $trans_methods , true , true );
9082
$messages = $messageBag->getMessages();
9183
$this->assertFalse( $return );
92-
$this->assertContains( 'The argument is not a valid regular expression:' , $messages[0][1] );
84+
$this->assertContains( 'The argument is not a valid regular expression:' , $messages[ 0 ][ 1 ] );
9385
}
9486
}

0 commit comments

Comments
 (0)