Skip to content

Commit

Permalink
Test files must have a namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 17, 2022
1 parent 4daa27c commit f7cd97a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Expand Up @@ -21,11 +21,11 @@ public function testMethods(): void
$this->analyse([__DIR__ . '/data/illegal-constructor-call-rule-test.php'], [
[
'Call to __construct() on an existing object is not allowed.',
16,
18,
],
[
'Call to __construct() on an existing object is not allowed.',
58,
60,
],
]);
}
Expand Down
Expand Up @@ -21,15 +21,15 @@ public function testMethods(): void
$this->analyse([__DIR__ . '/data/illegal-constructor-call-rule-test.php'], [
[
'Static call to __construct() is only allowed on a parent class in the constructor.',
29,
31,
],
[
'Static call to __construct() is only allowed on a parent class in the constructor.',
47,
49,
],
[
'Static call to __construct() is only allowed on a parent class in the constructor.',
48,
50,
],
]);
}
Expand Down
@@ -1,8 +1,10 @@
<?php

class ExtendedDateTimeWithMethodCall extends DateTimeImmutable
namespace IllegalConstructorMethodCall;

class ExtendedDateTimeWithMethodCall extends \DateTimeImmutable
{
public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null)
public function __construct(string $datetime = "now", ?\DateTimeZone $timezone = null)
{
// Avoid infinite loop
if (count(debug_backtrace()) > 1) {
Expand All @@ -11,28 +13,28 @@ public function __construct(string $datetime = "now", ?DateTimeZone $timezone =
$this->__construct($datetime, $timezone);
}

public function mutate(string $datetime = "now", ?DateTimeZone $timezone = null): void
public function mutate(string $datetime = "now", ?\DateTimeZone $timezone = null): void
{
$this->__construct($datetime, $timezone);
}
}

class ExtendedDateTimeWithParentCall extends DateTimeImmutable
class ExtendedDateTimeWithParentCall extends \DateTimeImmutable
{
public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null)
public function __construct(string $datetime = "now", ?\DateTimeZone $timezone = null)
{
parent::__construct($datetime, $timezone);
}

public function mutate(string $datetime = "now", ?DateTimeZone $timezone = null): void
public function mutate(string $datetime = "now", ?\DateTimeZone $timezone = null): void
{
parent::__construct($datetime, $timezone);
}
}

class ExtendedDateTimeWithSelfCall extends DateTimeImmutable
class ExtendedDateTimeWithSelfCall extends \DateTimeImmutable
{
public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null)
public function __construct(string $datetime = "now", ?\DateTimeZone $timezone = null)
{
// Avoid infinite loop
if (count(debug_backtrace()) > 1) {
Expand All @@ -42,7 +44,7 @@ public function __construct(string $datetime = "now", ?DateTimeZone $timezone =
ExtendedDateTimeWithSelfCall::__construct($datetime, $timezone);
}

public function mutate(string $datetime = "now", ?DateTimeZone $timezone = null): void
public function mutate(string $datetime = "now", ?\DateTimeZone $timezone = null): void
{
self::__construct($datetime, $timezone);
ExtendedDateTimeWithSelfCall::__construct($datetime, $timezone);
Expand Down

0 comments on commit f7cd97a

Please sign in to comment.