Skip to content

Commit bd01721

Browse files
committed
Import classes rather than using fully qualfied strings
1 parent 9854372 commit bd01721

File tree

8 files changed

+64
-50
lines changed

8 files changed

+64
-50
lines changed

tests/CLImateTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
use League\CLImate\Exceptions\InvalidArgumentException;
66
use League\CLImate\Exceptions\UnexpectedValueException;
7+
use League\CLImate\Tests\CustomObject\Basic;
78
use League\CLImate\Tests\CustomObject\BasicObject;
89
use League\CLImate\Tests\CustomObject\BasicObjectArgument;
10+
use League\CLImate\Tests\CustomObject\Dummy;
11+
use League\CLImate\Tests\CustomObject\Dynamic;
912

1013
class CLImateTest extends TestBase
1114
{
@@ -57,7 +60,7 @@ public function it_can_be_extended_using_a_basic_object_as_string()
5760
$this->shouldWrite("\e[mBy Custom Object: This is something my custom object is handling.\e[0m");
5861
$this->shouldHavePersisted();
5962

60-
$this->cli->extend('League\CLImate\Tests\CustomObject\Basic');
63+
$this->cli->extend(Basic::class);
6164
$this->cli->basic('This is something my custom object is handling.');
6265
}
6366

@@ -90,16 +93,16 @@ public function it_can_be_extended_using_a_basic_object_with_argument_setter()
9093
/** @test */
9194
public function it_can_be_extended_using_a_dynamic_object()
9295
{
93-
$this->cli->extend('League\CLImate\Tests\CustomObject\Dynamic');
96+
$this->cli->extend(Dynamic::class);
9497
$obj = $this->cli->dynamic();
9598

96-
$this->assertInstanceOf('League\CLImate\Tests\CustomObject\Dynamic', $obj);
99+
$this->assertInstanceOf(Dynamic::class, $obj);
97100
}
98101

99102
/** @test */
100103
public function it_will_yell_if_extending_and_class_doesnt_exist()
101104
{
102-
$class = 'League\CLImate\Tests\CustomObject\NowhereToBeFound';
105+
$class = "NoSuchClass";
103106
$this->expectException(UnexpectedValueException::class);
104107
$this->expectExceptionMessage("Class does not exist: {$class}");
105108
$this->cli->extend($class);
@@ -108,7 +111,7 @@ public function it_will_yell_if_extending_and_class_doesnt_exist()
108111
/** @test */
109112
public function it_will_yell_if_it_doesnt_implement_proper_interfaces()
110113
{
111-
$class = 'League\CLImate\Tests\CustomObject\Dummy';
114+
$class = Dummy::class;
112115
$this->expectException(InvalidArgumentException::class);
113116
$this->expectExceptionMessage("Class must implement either");
114117
$this->cli->extend($class);
@@ -123,7 +126,7 @@ public function it_will_accept_a_custom_key_for_an_extension()
123126
$this->shouldWrite("\e[mBy Custom Object: This is something my custom object is handling.\e[0m");
124127
$this->shouldHavePersisted();
125128

126-
$this->cli->extend('League\CLImate\Tests\CustomObject\Basic', 'myCustomMethod');
129+
$this->cli->extend(Basic::class, 'myCustomMethod');
127130
$this->cli->myCustomMethod('This is something my custom object is handling.');
128131
}
129132

@@ -134,8 +137,8 @@ public function it_will_accept_an_array_of_extensions()
134137
$this->shouldHavePersisted();
135138

136139
$extensions = [
137-
'League\CLImate\Tests\CustomObject\Basic',
138-
'League\CLImate\Tests\CustomObject\Dynamic',
140+
Basic::class,
141+
Dynamic::class,
139142
];
140143

141144
$this->cli->extend($extensions);
@@ -144,7 +147,7 @@ public function it_will_accept_an_array_of_extensions()
144147

145148
$obj = $this->cli->dynamic();
146149

147-
$this->assertInstanceOf('League\CLImate\Tests\CustomObject\Dynamic', $obj);
150+
$this->assertInstanceOf(Dynamic::class, $obj);
148151
}
149152

150153
/** @test */
@@ -154,8 +157,8 @@ public function it_will_accept_an_array_of_extensions_with_custom_keys()
154157
$this->shouldHavePersisted();
155158

156159
$extensions = [
157-
'whatever' => 'League\CLImate\Tests\CustomObject\Basic',
158-
'something' => 'League\CLImate\Tests\CustomObject\Dynamic',
160+
'whatever' => Basic::class,
161+
'something' => Dynamic::class,
159162
];
160163

161164
$this->cli->extend($extensions);
@@ -164,6 +167,6 @@ public function it_will_accept_an_array_of_extensions_with_custom_keys()
164167

165168
$obj = $this->cli->something();
166169

167-
$this->assertInstanceOf('League\CLImate\Tests\CustomObject\Dynamic', $obj);
170+
$this->assertInstanceOf(Dynamic::class, $obj);
168171
}
169172
}

tests/Decorator/Parser/AnsiTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use League\CLImate\Decorator\Parser\ParserFactory;
88
use League\CLImate\Decorator\Style;
99
use League\CLImate\Decorator\Tags;
10-
use League\CLImate\TerminalObject;
10+
use League\CLImate\TerminalObject\Basic\BasicTerminalObject;
1111
use League\CLImate\TerminalObject\Router\BasicRouter;
1212
use League\CLImate\Tests\TestBase;
1313
use League\CLImate\Util\System\Linux;
@@ -28,7 +28,8 @@ public function it_can_output_with_ansi()
2828

2929
$style = new Style();
3030
$parser = new Ansi($style->current(), new Tags($style->all()));
31-
$obj = Mockery::mock('League\CLImate\TerminalObject');
31+
32+
$obj = Mockery::mock(BasicTerminalObject::class);
3233
$obj->shouldReceive('result')->once()->andReturn("<green>I am green</green>");
3334
$obj->shouldReceive('sameLine')->once()->andReturn(false);
3435
$obj->shouldReceive('getParser')->once()->andReturn($parser);
@@ -52,7 +53,7 @@ public function it_can_output_without_ansi()
5253
$style = new Style();
5354
$parser = new NonAnsi($style->current(), new Tags($style->all()));
5455

55-
$obj = Mockery::mock('League\CLImate\TerminalObject');
56+
$obj = Mockery::mock(BasicTerminalObject::class);
5657
$obj->shouldReceive('result')->once()->andReturn("<green>I am not green</green>");
5758
$obj->shouldReceive('sameLine')->once()->andReturn(false);
5859
$obj->shouldReceive('getParser')->once()->andReturn($parser);
@@ -67,12 +68,12 @@ public function it_can_output_without_ansi()
6768
/** @test */
6869
public function it_will_recognize_non_ansi_systems()
6970
{
70-
$system = Mockery::mock('League\CLImate\Util\System\Windows');
71+
$system = Mockery::mock(Windows::class);
7172
$system->shouldReceive('hasAnsiSupport')->andReturn(false);
7273

7374
$parser = ParserFactory::getInstance($system, [], new Tags([]));
7475

75-
$this->assertInstanceOf('League\CLImate\Decorator\Parser\NonAnsi', $parser);
76+
$this->assertInstanceOf(NonAnsi::class, $parser);
7677
}
7778

7879
/**

tests/TerminalObject/Dynamic/Animation/AnimationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace League\CLImate\Tests\TerminalObject\Dynamic;
44

5+
use League\CLImate\TerminalObject\Helper\Sleeper;
56
use League\CLImate\Tests\TestBase;
67
use Mockery;
78

@@ -37,7 +38,7 @@ protected function blankLines($count = 1)
3738

3839
protected function getSleeper($count)
3940
{
40-
$sleeper = Mockery::mock('League\CLImate\TerminalObject\Helper\Sleeper');
41+
$sleeper = Mockery::mock(Sleeper::class);
4142
$sleeper->shouldReceive('sleep')->times($count);
4243

4344
return $sleeper;

tests/TestBase.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace League\CLImate\Tests;
44

55
use League\CLImate\CLImate;
6+
use League\CLImate\Util\Output;
7+
use League\CLImate\Util\Reader\Stdin;
8+
use League\CLImate\Util\System\Linux;
69
use Mockery;
710
use PHPUnit\Framework\TestCase;
811

@@ -28,13 +31,13 @@ public function setUp(): void
2831
{
2932
self::$functions = Mockery::mock();
3033

31-
$system = Mockery::mock('League\CLImate\Util\System\Linux');
34+
$system = Mockery::mock(Linux::class);
3235
$system->shouldReceive('hasAnsiSupport')->andReturn(true);
3336
$system->shouldReceive('width')->andReturn(80);
3437

3538
$this->util = new \League\CLImate\Util\UtilFactory($system);
36-
$this->output = Mockery::mock('League\CLImate\Util\Output');
37-
$this->reader = Mockery::mock('League\CLImate\Util\Reader\Stdin');
39+
$this->output = Mockery::mock(Output::class);
40+
$this->reader = Mockery::mock(Stdin::class);
3841

3942
$this->cli = new CLImate();
4043
$this->cli->setOutput($this->output);

tests/Util/OutputTest.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use League\CLImate\Exceptions\InvalidArgumentException;
66
use League\CLImate\Tests\TestBase;
77
use League\CLImate\Util\Output;
8+
use League\CLImate\Util\Writer\Buffer;
9+
use League\CLImate\Util\Writer\StdErr;
10+
use League\CLImate\Util\Writer\StdOut;
811
use Mockery;
912

1013
use function get_class;
@@ -17,7 +20,7 @@ class OutputTest extends TestBase
1720
*/
1821
public function it_can_output_content()
1922
{
20-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
23+
$out = Mockery::mock(StdOut::class);
2124
$out->shouldReceive('write')->once()->with("Oh, hey there." . \PHP_EOL);
2225

2326
$output = new Output();
@@ -33,7 +36,7 @@ public function it_can_output_content()
3336
*/
3437
public function it_can_output_content_without_a_new_line()
3538
{
36-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
39+
$out = Mockery::mock(StdOut::class);
3740
$out->shouldReceive('write')->once()->with("Oh, hey there.");
3841

3942
$output = new Output();
@@ -49,7 +52,7 @@ public function it_can_output_content_without_a_new_line()
4952
*/
5053
public function it_can_default_to_a_writer()
5154
{
52-
$error = Mockery::mock('League\CLImate\Util\Writer\StdErr');
55+
$error = Mockery::mock(StdErr::class);
5356
$error->shouldReceive('write')->once()->with("Oh, hey there.");
5457

5558
$output = new Output();
@@ -66,10 +69,10 @@ public function it_can_default_to_a_writer()
6669
*/
6770
public function it_can_default_to_multiple_writers()
6871
{
69-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
72+
$out = Mockery::mock(StdOut::class);
7073
$out->shouldReceive('write')->once()->with("Oh, hey there.");
7174

72-
$error = Mockery::mock('League\CLImate\Util\Writer\StdErr');
75+
$error = Mockery::mock(StdErr::class);
7376
$error->shouldReceive('write')->once()->with("Oh, hey there.");
7477

7578
$output = new Output();
@@ -87,10 +90,10 @@ public function it_can_default_to_multiple_writers()
8790
*/
8891
public function it_can_add_a_default()
8992
{
90-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
93+
$out = Mockery::mock(StdOut::class);
9194
$out->shouldReceive('write')->once()->with("Oh, hey there.");
9295

93-
$error = Mockery::mock('League\CLImate\Util\Writer\StdErr');
96+
$error = Mockery::mock(StdErr::class);
9497
$error->shouldReceive('write')->once()->with("Oh, hey there.");
9598

9699
$output = new Output();
@@ -109,10 +112,10 @@ public function it_can_add_a_default()
109112
*/
110113
public function it_can_handle_multiple_writers_for_one_key()
111114
{
112-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
115+
$out = Mockery::mock(StdOut::class);
113116
$out->shouldReceive('write')->once()->with('Oh, hey there.');
114117

115-
$error = Mockery::mock('League\CLImate\Util\Writer\StdErr');
118+
$error = Mockery::mock(StdErr::class);
116119
$error->shouldReceive('write')->once()->with('Oh, hey there.');
117120

118121
$output = new Output();
@@ -129,10 +132,10 @@ public function it_can_handle_multiple_writers_for_one_key()
129132
*/
130133
public function it_can_take_existing_writer_keys_and_resolve_them()
131134
{
132-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
135+
$out = Mockery::mock(StdOut::class);
133136
$out->shouldReceive('write')->once()->with('Oh, hey there.');
134137

135-
$error = Mockery::mock('League\CLImate\Util\Writer\StdErr');
138+
$error = Mockery::mock(StdErr::class);
136139
$error->shouldReceive('write')->once()->with('Oh, hey there.');
137140

138141
$output = new Output();
@@ -148,9 +151,9 @@ public function it_can_take_existing_writer_keys_and_resolve_them()
148151
/** @test */
149152
public function it_can_get_the_available_writers()
150153
{
151-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
152-
$error = Mockery::mock('League\CLImate\Util\Writer\StdErr');
153-
$buffer = Mockery::mock('League\CLImate\Util\Writer\Buffer');
154+
$out = Mockery::mock(StdOut::class);
155+
$error = Mockery::mock(StdErr::class);
156+
$buffer = Mockery::mock(Buffer::class);
154157

155158
$output = new Output();
156159

@@ -185,7 +188,7 @@ public function it_can_get_the_available_writers()
185188
/** @test */
186189
public function it_will_yell_if_writer_does_not_implement_writer_interface()
187190
{
188-
$out = Mockery::mock('League\CLImate\Util\Writer\Wat');
191+
$out = Mockery::mock();
189192
$output = new Output();
190193

191194
$this->expectException(InvalidArgumentException::class);
@@ -211,10 +214,10 @@ public function it_will_yell_if_trying_to_add_a_non_existent_nested_writer_key()
211214
*/
212215
public function it_can_write_to_a_non_default_writer_once()
213216
{
214-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
217+
$out = Mockery::mock(StdOut::class);
215218
$out->shouldReceive('write')->once()->with('Second time.');
216219

217-
$error = Mockery::mock('League\CLImate\Util\Writer\StdErr');
220+
$error = Mockery::mock(StdErr::class);
218221
$error->shouldReceive('write')->once()->with('First time.');
219222

220223
$output = new Output();
@@ -234,10 +237,10 @@ public function it_can_write_to_a_non_default_writer_once()
234237
*/
235238
public function it_will_persist_writer_if_told_to()
236239
{
237-
$out = Mockery::mock('League\CLImate\Util\Writer\StdOut');
240+
$out = Mockery::mock(StdOut::class);
238241
$out->shouldReceive('write')->once()->with('Second time.');
239242

240-
$error = Mockery::mock('League\CLImate\Util\Writer\StdErr');
243+
$error = Mockery::mock(StdErr::class);
241244
$error->shouldReceive('write')->times(3)->with('First time.');
242245

243246
$output = new Output();
@@ -258,7 +261,7 @@ public function it_will_persist_writer_if_told_to()
258261
/** @test */
259262
public function it_can_retrieve_a_writer()
260263
{
261-
$buffer = Mockery::mock('League\CLImate\Util\Writer\Buffer');
264+
$buffer = Mockery::mock(Buffer::class);
262265
$buffer->shouldReceive('write')->once()->with('Oh, hey there.');
263266
$buffer->shouldReceive('get')->once()->andReturn('Oh, hey there.');
264267

tests/Util/System/LinuxTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace League\CLImate\Tests\Util\System;
44

55
use League\CLImate\Tests\TestBase;
6+
use League\CLImate\Util\System\Linux;
67
use Mockery;
78

89
class LinuxTest extends TestBase
910
{
1011
/** @test */
1112
public function it_can_get_the_width()
1213
{
13-
$system = Mockery::mock('League\CLImate\Util\System\Linux')
14+
$system = Mockery::mock(Linux::class)
1415
->makePartial()
1516
->shouldAllowMockingProtectedMethods();
1617

@@ -22,7 +23,7 @@ public function it_can_get_the_width()
2223
/** @test */
2324
public function it_will_return_null_if_width_is_not_numeric()
2425
{
25-
$system = Mockery::mock('League\CLImate\Util\System\Linux')
26+
$system = Mockery::mock(Linux::class)
2627
->makePartial()
2728
->shouldAllowMockingProtectedMethods();
2829

@@ -34,7 +35,7 @@ public function it_will_return_null_if_width_is_not_numeric()
3435
/** @test */
3536
public function it_can_get_the_height()
3637
{
37-
$system = Mockery::mock('League\CLImate\Util\System\Linux')
38+
$system = Mockery::mock(Linux::class)
3839
->makePartial()
3940
->shouldAllowMockingProtectedMethods();
4041

@@ -46,7 +47,7 @@ public function it_can_get_the_height()
4647
/** @test */
4748
public function it_will_return_null_if_height_is_not_numeric()
4849
{
49-
$system = Mockery::mock('League\CLImate\Util\System\Linux')
50+
$system = Mockery::mock(Linux::class)
5051
->makePartial()
5152
->shouldAllowMockingProtectedMethods();
5253

0 commit comments

Comments
 (0)