Skip to content

Commit 258d21c

Browse files
committed
chore(analyzer): add more tests
Signed-off-by: azjezz <[email protected]>
1 parent 6c4fd3a commit 258d21c

19 files changed

+246
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
abstract class AbstractClass
4+
{
5+
abstract public function doSomething(): void;
6+
}
7+
8+
/**
9+
* @mago-expect analysis:abstract-instantiation
10+
* @mago-expect analysis:impossible-assignment
11+
*/
12+
function testAbstractInstantiation(): void
13+
{
14+
$_ = new AbstractClass();
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
class MyClass
4+
{
5+
/**
6+
* @mago-expect analysis:assignment-to-this
7+
*/
8+
public function reassignThis(): void
9+
{
10+
$this = new MyClass();
11+
}
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
enum Status
4+
{
5+
case Active;
6+
case Inactive;
7+
}
8+
9+
/**
10+
* @mago-expect analysis:enum-instantiation
11+
* @mago-expect analysis:impossible-assignment
12+
*/
13+
function testEnumInstantiation(): void
14+
{
15+
$_ = new Status();
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
interface MyInterface
4+
{
5+
public function doSomething(): void;
6+
}
7+
8+
/**
9+
* @mago-expect analysis:interface-instantiation
10+
* @mago-expect analysis:impossible-assignment
11+
*/
12+
function testInterfaceInstantiation(): void
13+
{
14+
$_ = new MyInterface();
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
/**
4+
* @mago-expect analysis:invalid-break
5+
*/
6+
function testInvalidBreak(): void
7+
{
8+
break;
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
/**
4+
* @mago-expect analysis:invalid-clone
5+
* @mago-expect analysis:impossible-assignment
6+
*/
7+
function testInvalidClone(): void
8+
{
9+
$value = 42;
10+
$_ = clone $value;
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
/**
4+
* @mago-expect analysis:invalid-continue
5+
*/
6+
function testInvalidContinue(): void
7+
{
8+
continue;
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* @mago-expect analysis:invalid-iterator
5+
* @mago-expect analysis:mixed-argument
6+
* @mago-expect analysis:mixed-assignment
7+
*/
8+
function testInvalidIterator(): void
9+
{
10+
$notIterable = 42;
11+
foreach ($notIterable as $item) {
12+
echo $item;
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
/**
4+
* @mago-expect analysis:invalid-throw
5+
*/
6+
function testInvalidThrow(): void
7+
{
8+
throw 'not an exception';
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
class MyClass
4+
{
5+
public function doSomething(): void {}
6+
}
7+
8+
/**
9+
* @mago-expect analysis:method-access-on-null
10+
*/
11+
function testMethodAccessOnNull(): void
12+
{
13+
$obj = null;
14+
$obj->doSomething();
15+
}

0 commit comments

Comments
 (0)