Skip to content

Commit c7d012d

Browse files
authored
Merge pull request #9259 from samsonasik/refactor-move-property-to-local-variable
refactor: Move property to local variable on usage only in setUp() method in tests
2 parents 52c74b5 + 8628f12 commit c7d012d

File tree

14 files changed

+32
-57
lines changed

14 files changed

+32
-57
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16429,12 +16429,6 @@
1642916429
'count' => 5,
1643016430
'path' => __DIR__ . '/tests/system/Pager/PagerTest.php',
1643116431
];
16432-
$ignoreErrors[] = [
16433-
// identifier: missingType.iterableValue
16434-
'message' => '#^Property CodeIgniter\\\\Publisher\\\\PublisherOutputTest\\:\\:\\$structure type has no value type specified in iterable type array\\.$#',
16435-
'count' => 1,
16436-
'path' => __DIR__ . '/tests/system/Publisher/PublisherOutputTest.php',
16437-
];
1643816432
$ignoreErrors[] = [
1643916433
// identifier: missingType.iterableValue
1644016434
'message' => '#^Method CodeIgniter\\\\Publisher\\\\PublisherRestrictionsTest\\:\\:provideDefaultPublicRestrictions\\(\\) return type has no value type specified in iterable type iterable\\.$#',

tests/system/CLI/ConsoleTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ final class ConsoleTest extends CIUnitTestCase
3030
{
3131
use StreamFilterTrait;
3232

33-
private DotEnv $env;
34-
3533
protected function setUp(): void
3634
{
3735
parent::setUp();
3836

39-
$this->env = new DotEnv(ROOTPATH);
40-
$this->env->load();
37+
$env = new DotEnv(ROOTPATH);
38+
$env->load();
4139

4240
// Set environment values that would otherwise stop the framework from functioning during tests.
4341
if (! isset($_SERVER['app.baseURL'])) {

tests/system/Cache/Handlers/MemcachedHandlerTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#[Group('CacheLive')]
2626
final class MemcachedHandlerTest extends AbstractHandlerTestCase
2727
{
28-
private Cache $config;
29-
3028
private static function getKeyArray()
3129
{
3230
return [
@@ -44,9 +42,9 @@ protected function setUp(): void
4442
$this->markTestSkipped('Memcached extension not loaded.');
4543
}
4644

47-
$this->config = new Cache();
45+
$config = new Cache();
4846

49-
$this->handler = new MemcachedHandler($this->config);
47+
$this->handler = new MemcachedHandler($config);
5048

5149
$this->handler->initialize();
5250
}

tests/system/CodeIgniterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
final class CodeIgniterTest extends CIUnitTestCase
4848
{
4949
private CodeIgniter $codeigniter;
50-
protected $routes;
5150

5251
#[WithoutErrorHandler]
5352
protected function setUp(): void

tests/system/Config/DotEnvTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
final class DotEnvTest extends CIUnitTestCase
3333
{
3434
private ?vfsStreamDirectory $root;
35-
private string $path;
3635
private string $fixturesFolder;
3736

3837
#[WithoutErrorHandler]
@@ -42,8 +41,8 @@ protected function setUp(): void
4241

4342
$this->root = vfsStream::setup();
4443
$this->fixturesFolder = $this->root->url();
45-
$this->path = TESTPATH . 'system/Config/fixtures';
46-
vfsStream::copyFromFileSystem($this->path, $this->root);
44+
$path = TESTPATH . 'system/Config/fixtures';
45+
vfsStream::copyFromFileSystem($path, $this->root);
4746

4847
$file = 'unreadable.env';
4948
$path = rtrim($this->fixturesFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;

tests/system/ControllerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#[Group('Others')]
4141
final class ControllerTest extends CIUnitTestCase
4242
{
43-
private App $config;
4443
private ?Controller $controller = null;
4544

4645
/**
@@ -59,9 +58,9 @@ protected function setUp(): void
5958
{
6059
parent::setUp();
6160

62-
$this->config = new App();
63-
$this->request = new IncomingRequest($this->config, new SiteURI($this->config), null, new UserAgent());
64-
$this->response = new Response($this->config);
61+
$config = new App();
62+
$this->request = new IncomingRequest($config, new SiteURI($config), null, new UserAgent());
63+
$this->response = new Response($config);
6564
$this->logger = Services::logger();
6665
}
6766

tests/system/Files/FileWithVfsTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ final class FileWithVfsTest extends CIUnitTestCase
2626
{
2727
// For VFS stuff
2828
private ?vfsStreamDirectory $root = null;
29-
private string $path;
3029
private string $start;
3130
private File $file;
3231

@@ -35,8 +34,8 @@ protected function setUp(): void
3534
parent::setUp();
3635

3736
$this->root = vfsStream::setup();
38-
$this->path = '_support/Files/';
39-
vfsStream::copyFromFileSystem(TESTPATH . $this->path, $this->root);
37+
$path = '_support/Files/';
38+
vfsStream::copyFromFileSystem(TESTPATH . $path, $this->root);
4039
$this->start = $this->root->url() . '/';
4140
$this->file = new File($this->start . 'able/apple.php');
4241
}

tests/system/HTTP/Files/FileMovingTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@
2626
final class FileMovingTest extends CIUnitTestCase
2727
{
2828
private ?vfsStreamDirectory $root;
29-
private string $path;
30-
private string $start;
3129
private string $destination;
3230

3331
protected function setUp(): void
3432
{
3533
parent::setUp();
3634

3735
$this->root = vfsStream::setup();
38-
$this->path = '_support/Files/';
39-
vfsStream::copyFromFileSystem(TESTPATH . $this->path, $this->root);
40-
$this->start = $this->root->url() . '/';
36+
$path = '_support/Files/';
37+
vfsStream::copyFromFileSystem(TESTPATH . $path, $this->root);
38+
$start = $this->root->url() . '/';
4139

42-
$this->destination = $this->start . 'destination';
40+
$this->destination = $start . 'destination';
4341
if (is_dir($this->destination)) {
4442
rmdir($this->destination);
4543
}

tests/system/Helpers/CookieHelperTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#[Group('Others')]
3434
final class CookieHelperTest extends CIUnitTestCase
3535
{
36-
private IncomingRequest $request;
3736
private string $name;
3837
private string $value;
3938
private int $expire;
@@ -51,8 +50,8 @@ protected function setUp(): void
5150

5251
Services::injectMock('response', new MockResponse(new App()));
5352
$this->response = Services::response();
54-
$this->request = new IncomingRequest(new App(), new SiteURI(new App()), null, new UserAgent());
55-
Services::injectMock('request', $this->request);
53+
$request = new IncomingRequest(new App(), new SiteURI(new App()), null, new UserAgent());
54+
Services::injectMock('request', $request);
5655

5756
helper('cookie');
5857
}

tests/system/Images/BaseHandlerTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use CodeIgniter\Images\Handlers\BaseHandler;
2020
use CodeIgniter\Test\CIUnitTestCase;
2121
use org\bovigo\vfs\vfsStream;
22-
use org\bovigo\vfs\vfsStreamDirectory;
2322
use PHPUnit\Framework\Attributes\Group;
2423

2524
/**
@@ -35,7 +34,6 @@
3534
#[Group('Others')]
3635
final class BaseHandlerTest extends CIUnitTestCase
3736
{
38-
private vfsStreamDirectory $root;
3937
private string $origin;
4038
private string $start;
4139
private string $path;
@@ -47,21 +45,21 @@ protected function setUp(): void
4745
}
4846

4947
// create virtual file system
50-
$this->root = vfsStream::setup();
48+
$root = vfsStream::setup();
5149
// copy our support files
5250
$this->origin = SUPPORTPATH . 'Images/';
53-
vfsStream::copyFromFileSystem($this->origin, $this->root);
51+
vfsStream::copyFromFileSystem($this->origin, $root);
5452
// make subfolders
5553
$structure = [
5654
'work' => [],
5755
'wontwork' => [],
5856
];
5957
vfsStream::create($structure);
6058
// with one of them read only
61-
$this->root->getChild('wontwork')->chmod(0400);
59+
$root->getChild('wontwork')->chmod(0400);
6260

6361
// for VFS tests
64-
$this->start = $this->root->url() . '/';
62+
$this->start = $root->url() . '/';
6563
$this->path = $this->start . 'ci-logo.png';
6664
}
6765

0 commit comments

Comments
 (0)