Skip to content

Commit 6cf8068

Browse files
committed
tests
1 parent 85c709d commit 6cf8068

File tree

5 files changed

+151
-0
lines changed

5 files changed

+151
-0
lines changed

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,30 @@ public function testBug12131(): void
689689
]);
690690
}
691691

692+
public function testBug6398(): void
693+
{
694+
$this->checkExplicitMixed = true;
695+
$this->analyse([__DIR__ . '/data/bug-6398.php'], []);
696+
}
697+
698+
public function testBug6571(): void
699+
{
700+
$this->checkExplicitMixed = true;
701+
$this->analyse([__DIR__ . '/data/bug-6571.php'], []);
702+
}
703+
704+
public function testBug7880(): void
705+
{
706+
$this->checkExplicitMixed = true;
707+
$this->analyse([__DIR__ . '/data/bug-7880.php'], []);
708+
}
709+
710+
public function testBug12565(): void
711+
{
712+
$this->checkExplicitMixed = true;
713+
$this->analyse([__DIR__ . '/data/bug-12565.php'], []);
714+
}
715+
692716
public function testShortBodySetHook(): void
693717
{
694718
if (PHP_VERSION_ID < 80400) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12565;
4+
5+
class EntryType {
6+
public string $title = '';
7+
public string $subTitle = '';
8+
}
9+
/**
10+
* @implements \ArrayAccess<int, EntryType>
11+
*/
12+
class ArrayLike implements \ArrayAccess {
13+
14+
/** @var EntryType[] */
15+
private array $values = [];
16+
public function offsetExists(mixed $offset): bool
17+
{
18+
return isset($this->values[$offset]);
19+
}
20+
21+
public function offsetGet(mixed $offset): EntryType
22+
{
23+
return $this->values[$offset] ?? new EntryType();
24+
}
25+
26+
public function offsetSet(mixed $offset, mixed $value): void
27+
{
28+
$this->values[$offset] = $value;
29+
}
30+
31+
public function offsetUnset(mixed $offset): void
32+
{
33+
unset($this->values[$offset]);
34+
}
35+
}
36+
37+
class Wrapper {
38+
public ?ArrayLike $myArrayLike;
39+
40+
public function __construct()
41+
{
42+
$this->myArrayLike = new ArrayLike();
43+
44+
}
45+
}
46+
47+
$baz = new Wrapper();
48+
$baz->myArrayLike = new ArrayLike();
49+
$baz->myArrayLike[1] = new EntryType();
50+
$baz->myArrayLike[1]->title = "Test";
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Bug6398;
4+
5+
class AsyncTask{
6+
/**
7+
* @phpstan-var \ArrayObject<int, array<string, mixed>>|null
8+
*/
9+
private static $threadLocalStorage = null;
10+
11+
/**
12+
* @param mixed $complexData the data to store
13+
*/
14+
protected function storeLocal(string $key, $complexData) : void{
15+
if(self::$threadLocalStorage === null){
16+
self::$threadLocalStorage = new \ArrayObject();
17+
}
18+
self::$threadLocalStorage[spl_object_id($this)][$key] = $complexData;
19+
}
20+
21+
/**
22+
* @return mixed
23+
*/
24+
protected function fetchLocal(string $key){
25+
$id = spl_object_id($this);
26+
if(self::$threadLocalStorage === null or !isset(self::$threadLocalStorage[$id][$key])){
27+
throw new \InvalidArgumentException("No matching thread-local data found on this thread");
28+
}
29+
30+
return self::$threadLocalStorage[$id][$key];
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types = 1); // lint >= 7.4
2+
3+
namespace Bug6571;
4+
5+
interface ClassLoader{}
6+
7+
class HelloWorld
8+
{
9+
/** @var \Threaded|\ClassLoader[]|null */
10+
private ?\Threaded $classLoaders = null;
11+
12+
/**
13+
* @param \ClassLoader[] $autoloaders
14+
*/
15+
public function setClassLoaders(?array $autoloaders = null) : void{
16+
if($autoloaders === null){
17+
$autoloaders = [];
18+
}
19+
20+
if($this->classLoaders === null){
21+
$this->classLoaders = new \Threaded();
22+
}else{
23+
foreach($this->classLoaders as $k => $autoloader){
24+
unset($this->classLoaders[$k]);
25+
}
26+
}
27+
foreach($autoloaders as $autoloader){
28+
$this->classLoaders[] = $autoloader;
29+
}
30+
}
31+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7880;
4+
5+
class C {
6+
/** @var array{a: string, b: string}|null */
7+
private $a = null;
8+
9+
public function foo(): void {
10+
if ($this->a !== null) {
11+
$this->a['b'] = "baz";
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)