Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
#[\DelayedTargetValidation] with #[\Override]: non-overrides still error (class constant)
--FILE--
<?php

class DemoClass {

#[DelayedTargetValidation]
#[Override] // Does something here
public const CLASS_CONSTANT = 'FOO';
}

?>
--EXPECTF--
Fatal error: DemoClass::CLASS_CONSTANT has #[\Override] attribute, but no matching parent constant exists in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Base {
set => $value;
}

public const CLASS_CONST = '';

public function printVal() {
echo __METHOD__ . "\n";
}
Expand All @@ -34,7 +36,7 @@ class DemoClass extends Base {
}

#[DelayedTargetValidation]
#[Override] // Does nothing here
#[Override] // Does something here
public const CLASS_CONST = 'FOO';

public function __construct(
Expand Down
15 changes: 15 additions & 0 deletions Zend/tests/attributes/override/constants/anon_failure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
#[\Override]: Constants - anonymous class, no interface or parent class
--FILE--
<?php

new class () {
#[\Override]
public const C = 'C';
};

echo "Done";

?>
--EXPECTF--
Fatal error: class@anonymous::C has #[\Override] attribute, but no matching parent constant exists in %s on line %d
19 changes: 19 additions & 0 deletions Zend/tests/attributes/override/constants/anon_interface.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Constants - anonymous class overrides interface
--FILE--
<?php

interface IFace {
public const I = 'I';
}

new class () implements IFace {
#[\Override]
public const I = 'Changed';
};

echo "Done";

?>
--EXPECT--
Done
19 changes: 19 additions & 0 deletions Zend/tests/attributes/override/constants/anon_parent.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Constants - anonymous class overrides parent class
--FILE--
<?php

class Base {
public const C = 'C';
}

new class () extends Base {
#[\Override]
public const C = 'Changed';
};

echo "Done";

?>
--EXPECT--
Done
39 changes: 39 additions & 0 deletions Zend/tests/attributes/override/constants/basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
#[\Override]: Constants - basic
--FILE--
<?php

interface I {
public const I = 'I';
}

interface II extends I {
#[\Override]
public const I = 'I';
}

class P {
public const C1 = 'C1';
public const C2 = 'C2';
}

class PP extends P {
#[\Override]
public const C1 = 'C1';
public const C2 = 'C2';
}

class C extends PP implements I {
#[\Override]
public const I = 'I';
#[\Override]
public const C1 = 'C1';
public const C2 = 'C2';
public const C = 'C';
}

echo "Done";

?>
--EXPECT--
Done
15 changes: 15 additions & 0 deletions Zend/tests/attributes/override/constants/failure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
#[\Override]: Constants - no interface or parent class
--FILE--
<?php

class Demo {
#[\Override]
public const C = 'C';
}

echo "Done";

?>
--EXPECTF--
Fatal error: Demo::C has #[\Override] attribute, but no matching parent constant exists in %s on line %d
15 changes: 15 additions & 0 deletions Zend/tests/attributes/override/constants/interface_failure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
#[\Override]: Constants - no parent interface
--FILE--
<?php

interface IFace {
#[\Override]
public const I = 'I';
}

echo "Done";

?>
--EXPECTF--
Fatal error: IFace::I has #[\Override] attribute, but no matching parent constant exists in %s on line %d
19 changes: 19 additions & 0 deletions Zend/tests/attributes/override/constants/trait_failure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Constants - on a trait, no interface or parent class
--FILE--
<?php

trait DemoTrait {
#[\Override]
public const T = 'T';
}

class UsesTrait {
use DemoTrait;
}

echo "Done";

?>
--EXPECTF--
Fatal error: UsesTrait::T has #[\Override] attribute, but no matching parent constant exists in %s on line %d
23 changes: 23 additions & 0 deletions Zend/tests/attributes/override/constants/trait_interface.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
#[\Override]: Constants - on a trait, overrides interface
--FILE--
<?php

trait DemoTrait {
#[\Override]
public const C = 'Changed';
}

interface IFace {
public const C = 'C';
}

class UsesTrait implements IFace {
use DemoTrait;
}

echo "Done";

?>
--EXPECT--
Done
23 changes: 23 additions & 0 deletions Zend/tests/attributes/override/constants/trait_parent.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
#[\Override]: Constants - on a trait, overrides parent class
--FILE--
<?php

trait DemoTrait {
#[\Override]
public const C = 'Changed';
}

class Base {
public const C = 'C';
}

class UsesTrait extends Base {
use DemoTrait;
}

echo "Done";

?>
--EXPECT--
Done
21 changes: 21 additions & 0 deletions Zend/tests/attributes/override/constants/trait_redeclared.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
#[\Override]: Constants - trait constant redeclared, not overridden
--FILE--
<?php

trait DemoTrait {
public const T = 'T';
}

class UsesTrait {
use DemoTrait;

#[\Override]
public const T = 'T';
}

echo "Done";

?>
--EXPECTF--
Fatal error: UsesTrait::T has #[\Override] attribute, but no matching parent constant exists in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
#[\Override]: Constants - trait constant redeclared, overrides interface
--FILE--
<?php

interface IFace {
public const I = 'I';
}

trait DemoTrait {
public const I = 'I';
}

class UsesTrait implements IFace {
use DemoTrait;

#[\Override]
public const I = 'I';
}

echo "Done";

?>
--EXPECT--
Done
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
#[\Override]: Constants - trait constant redeclared, overrides parent class
--FILE--
<?php

class Base {
public const I = 'I';
}

trait DemoTrait {
public const I = 'I';
}

class UsesTrait extends Base {
use DemoTrait;

#[\Override]
public const I = 'I';
}

echo "Done";

?>
--EXPECT--
Done
15 changes: 15 additions & 0 deletions Zend/tests/attributes/override/constants/trait_unused.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
#[\Override]: Constants - on a trait, unused
--FILE--
<?php

trait Demo {
#[\Override]
public const T = 'T';
}

echo "Done";

?>
--EXPECT--
Done
19 changes: 19 additions & 0 deletions Zend/tests/attributes/override/constants/visibility_01.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Constants - private constant not overridden (by public constant)
--FILE--
<?php

class Base {
private const C = 'C';
}

class Child extends Base {
#[\Override]
public const C = 'Changed';
}

echo "Done";

?>
--EXPECTF--
Fatal error: Child::C has #[\Override] attribute, but no matching parent constant exists in %s on line %d
19 changes: 19 additions & 0 deletions Zend/tests/attributes/override/constants/visibility_02.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Constants - private constant not overridden (by private constant)
--FILE--
<?php

class Base {
private const C = 'C';
}

class Child extends Base {
#[\Override]
private const C = 'Changed';
}

echo "Done";

?>
--EXPECTF--
Fatal error: Child::C has #[\Override] attribute, but no matching parent constant exists in %s on line %d
19 changes: 19 additions & 0 deletions Zend/tests/attributes/override/constants/visibility_03.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Constants - protected constant is overridden (by public constant)
--FILE--
<?php

class Base {
protected const C = 'C';
}

class Child extends Base {
#[\Override]
public const C = 'Changed';
}

echo "Done";

?>
--EXPECT--
Done
19 changes: 19 additions & 0 deletions Zend/tests/attributes/override/constants/visibility_04.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Constants - protected constant is overridden (by protected constant)
--FILE--
<?php

class Base {
protected const C = 'C';
}

class Child extends Base {
#[\Override]
protected const C = 'Changed';
}

echo "Done";

?>
--EXPECT--
Done
Loading