Skip to content

Commit 4b25e4e

Browse files
mleuteneggerSam Minnee
andauthored
add: github action tests (#3)
* add: github action tests * fix: test definitions * update test file * enable pr * enable pr 2nd * Pulls/phpstan 012 (#4) * API: Upgrade to phpstan 0.12 Unfortunately retaining 0.11 support isn’t feasible but that seems like an acceptable tradeoff. Note that some of the type-hinting of DataLists will now be doable with phpstan’s template features - we can type hint DataList<Member> for example, and we can commit some @phpstan-return clauses to the core framework to support this. * FIX: Don’t rely on old .x-dev branches for testing. * FIX: Update the install instructions to account for the use of phpstan 0.12 Co-authored-by: Sam Minnee <sam@silverstripe.com> * remove travis again * reenable version upgrade * fix stan * fix: testcase naming * allow php 8 * fix unittests * check tests * limit * use tests from phpstan * remove mixed * check out type return * ... * DataObjectGetStaticReturnTypeExtensionTest * add correct use statement * reset * fix: className * change: use assertNativeType * update config * test * increase memory * stop recursion * exclude impossible configs * do not check tested files * reset * reset * fix tests * add: return checks * add more dataobject tests * add: all tests * FIX PHPSTAN * phpcs * remove travis * cs Co-authored-by: Sam Minnee <sam@silverstripe.com>
1 parent bce0907 commit 4b25e4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+853
-743
lines changed

.github/workflows/tests.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: 🎭 Tests
2+
on:
3+
push:
4+
paths-ignore:
5+
- .chglog/**
6+
- .github/**
7+
- '!.github/workflows/tests.yml'
8+
- .editorconfig
9+
- .gitattributes
10+
- .gitignore
11+
- .htaccess
12+
- '**.md'
13+
branches:
14+
- master
15+
pull_request:
16+
paths-ignore:
17+
- .chglog/**
18+
- .github/**
19+
- '!.github/workflows/tests.yml'
20+
- .editorconfig
21+
- .gitattributes
22+
- .gitignore
23+
- .htaccess
24+
- '**.md'
25+
branches:
26+
- master
27+
env:
28+
DB: MYSQL
29+
PDO: 1
30+
SS_ENVIRONMENT_TYPE: "dev"
31+
jobs:
32+
phpunit:
33+
name: 🧩 PHPUnit
34+
runs-on: ubuntu-latest
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
php:
39+
- '7.4'
40+
- '8.0'
41+
recipe:
42+
- 4.3.*
43+
- 4.x-dev
44+
exclude:
45+
- php: '8.0'
46+
recipe: 4.3.*
47+
container: brettt89/silverstripe-web:${{ matrix.php }}-apache
48+
services:
49+
database:
50+
image: mysql:5.7
51+
ports:
52+
- 3306:3306
53+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
54+
env:
55+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
56+
env:
57+
SS_DEFAULT_ADMIN_USERNAME: admin
58+
SS_DEFAULT_ADMIN_PASSWORD: admin
59+
SS_DATABASE_SERVER: database
60+
SS_DATABASE_NAME: ss_default_${{ matrix.php }}
61+
SS_DATABASE_USERNAME: root
62+
SS_DATABASE_PASSWORD: ''
63+
SS_ENVIRONMENT_TYPE: dev
64+
RECIPE_CMS_VERSION: ${{ matrix.recipe }}
65+
steps:
66+
- name: Install Composer
67+
run: |
68+
curl \
69+
-sS https://getcomposer.org/installer \
70+
| php && \
71+
mv -f composer.phar /usr/local/bin/composer
72+
- name: Install git
73+
run: |
74+
apt update && apt-get install git -yqq
75+
- name: Checkout code
76+
uses: actions/checkout@v2
77+
- name: install dependencies
78+
run: |
79+
composer require --no-update silverstripe/recipe-cms:$RECIPE_CMS_VERSION &&\
80+
composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
81+
- name: run phpunit
82+
run: vendor/bin/phpunit -d memory_limit=500M -c "tests/phpunit.xml" tests/
83+
# - name: generate coverage
84+
# run: phpdbg -qrr vendor/bin/phpunit -dmemory_limit=512M --coverage-clover=coverage.xml tests/
85+
# if: ${{ matrix.php == '7.4' }}
86+
# - name: submit coverage
87+
# uses: codecov/codecov-action@v2
88+
# with:
89+
# token: ${{ secrets.CODECOV_TOKEN }}
90+
# files: ./coverage.xml
91+
# if: ${{ matrix.php == '7.4' }}
92+
phpstan:
93+
name: 🔍 PHPStan
94+
runs-on: ubuntu-latest
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
php:
99+
- '7.4'
100+
- '8.0'
101+
recipe:
102+
- 4.3.*
103+
- 4.x-dev
104+
exclude:
105+
- php: '8.0'
106+
recipe: 4.3.*
107+
container: brettt89/silverstripe-web:7.4-apache
108+
env:
109+
RECIPE_CMS_VERSION: ${{ matrix.recipe }}
110+
steps:
111+
- name: Install Composer
112+
run: |
113+
curl \
114+
-sS https://getcomposer.org/installer \
115+
| php && \
116+
mv -f composer.phar /usr/local/bin/composer
117+
- name: Install git
118+
run: |
119+
apt update && apt-get install git -yqq
120+
- name: Checkout code
121+
uses: actions/checkout@v2
122+
- name: install dependencies
123+
run: |
124+
composer require --no-update silverstripe/recipe-cms:$RECIPE_CMS_VERSION &&\
125+
composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
126+
- name: run phpstan
127+
run: vendor/bin/phpstan analyse src/ tests/ -c "tests/phpstan.neon" -a "tests/bootstrap-phpstan.php" --level 4 --memory-limit 1G
128+
phpcs:
129+
name: 🔮 PHPcs
130+
runs-on: ubuntu-latest
131+
steps:
132+
- name: Checkout code
133+
uses: actions/checkout@v2
134+
- name: lint source
135+
uses: chindit/actions-phpcs@master
136+
with:
137+
dir: src/
138+
- name: lint tests
139+
uses: chindit/actions-phpcs@master
140+
with:
141+
dir: tests/

.old-travis.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ composer require --dev symbiote/silverstripe-phpstan:1.0.0 phpstan/phpstan-shim:
2525

2626
SilverStripe 4.X
2727
```
28-
composer require --dev symbiote/silverstripe-phpstan:2.0.0 phpstan/phpstan-shim:~0.11.0
28+
composer require --dev symbiote/silverstripe-phpstan
2929
```
3030

31-
NOTE: We recommend installing the phpstan-shim as currently in SilverStripe 3.X, the QueuedJobs module's dependence on superclosure forces the PHP-Parser dependency of PHPStan to be at a very outdated version.
31+
NOTE: Versions of PHPStan less than 0.12, we recommend installing the phpstan-shim as currently in SilverStripe 3.X,
32+
the QueuedJobs module's dependence on superclosure forces the PHP-Parser dependency of PHPStan to be at a very outdated
33+
version. From 0.12, the 'shim' install is the dfeault.
3234

3335
## Requirements
3436

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": "~7.1",
21+
"php": "~7.1 || ~8.0",
2222
"silverstripe/framework": "~4.3",
2323
"silverstripe/vendor-plugin": "^1.0",
2424
"phpstan/phpstan": "^1.5"

phpcs.xml.dist renamed to phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<description>Coding standard for SilverStripe 3.x</description>
44

55
<!-- Don't sniff third party libraries -->
6-
<exclude-pattern>*/vendor/*</exclude-pattern>
6+
<!-- <exclude-pattern>*/vendor/*</exclude-pattern> -->
77
<exclude-pattern>*/thirdparty/*</exclude-pattern>
88

99
<!-- Show progress and output sniff names on violation, and add colours -->

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ parameters:
99
- SilverStripe\ORM\DataObject
1010
- SilverStripe\ORM\DataObjectInterface
1111
- Symbiote\QueuedJobs\Services\AbstractQueuedJob # symbiote/silverstripe-queuedjobs module support
12-
excludes_analyse:
12+
excludePaths:
1313
- silverstripe-cache
1414
services:
1515
# This rule will throw an error if you `return false` from a RequestFilter::preRequest() method

src/Reflection/CachedMethod.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Type\Type;
99
use PHPStan\Type\MixedType;
1010
use PHPStan\Reflection\Php\PhpMethodReflection;
11+
use PHPStan\TrinaryLogic;
1112

1213
class CachedMethod implements MethodReflection
1314
{
@@ -25,13 +26,6 @@ class CachedMethod implements MethodReflection
2526
*/
2627
private $methodReflection;
2728

28-
/**
29-
*
30-
*
31-
* @var \PHPStan\Reflection\ClassReflection
32-
*/
33-
private $declaringClass;
34-
3529
public function __construct(PhpMethodReflection $methodReflection)
3630
{
3731
// Remove '_' from front of function
@@ -91,4 +85,39 @@ public function getVariants(): array
9185
{
9286
return $this->methodReflection->getVariants();
9387
}
88+
89+
public function isDeprecated(): TrinaryLogic
90+
{
91+
return TrinaryLogic::createNo();
92+
}
93+
94+
public function isFinal(): TrinaryLogic
95+
{
96+
return TrinaryLogic::createNo();
97+
}
98+
99+
public function getDeprecatedDescription(): ?string
100+
{
101+
return null;
102+
}
103+
104+
public function hasSideEffects(): TrinaryLogic
105+
{
106+
return TrinaryLogic::createNo();
107+
}
108+
109+
public function getThrowType(): ?Type
110+
{
111+
return null;
112+
}
113+
114+
public function isInternal(): TrinaryLogic
115+
{
116+
return TrinaryLogic::createNo();
117+
}
118+
119+
public function getDocComment(): ?string
120+
{
121+
return null;
122+
}
94123
}

src/Reflection/ComponentDBFieldProperty.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Reflection\PropertyReflection;
88
use PHPStan\Type\Type;
99
use PHPStan\Type\ObjectType;
10+
use PHPStan\TrinaryLogic;
1011

1112
class ComponentDBFieldProperty implements PropertyReflection
1213
{
@@ -42,7 +43,12 @@ public function __construct(string $name, ClassReflection $declaringClass, Objec
4243
$this->returnType = Utility::get_primitive_from_dbfield($className);
4344
}
4445

45-
public function getType(): Type
46+
public function getReadableType(): Type
47+
{
48+
return $this->returnType;
49+
}
50+
51+
public function getWritableType(): Type
4652
{
4753
return $this->returnType;
4854
}
@@ -76,4 +82,34 @@ public function isWritable(): bool
7682
{
7783
return true;
7884
}
85+
86+
public function isDeprecated(): TrinaryLogic
87+
{
88+
return TrinaryLogic::createNo();
89+
}
90+
91+
public function isInternal(): TrinaryLogic
92+
{
93+
return TrinaryLogic::createNo();
94+
}
95+
96+
public function getDeprecatedDescription(): ?string
97+
{
98+
return null;
99+
}
100+
101+
public function getDocComment(): ?string
102+
{
103+
return null;
104+
}
105+
106+
public function canChangeTypeAfterAssignment(): bool
107+
{
108+
return true;
109+
}
110+
111+
public function getName(): string
112+
{
113+
return $this->name;
114+
}
79115
}

src/Reflection/ComponentHasManyMethod.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
use PHPStan\Reflection\ClassMemberReflection;
99
use PHPStan\Reflection\MethodReflection;
1010
use PHPStan\Reflection\FunctionVariant;
11+
use PHPStan\Type\Generic\TemplateTypeMap;
1112
use PHPStan\Type\Type;
1213
use PHPStan\Type\ObjectType;
14+
use PHPStan\TrinaryLogic;
1315

1416
class ComponentHasManyMethod implements MethodReflection
1517
{
@@ -91,6 +93,8 @@ public function getVariants(): array
9193
if ($this->variants === null) {
9294
$this->variants = [
9395
new FunctionVariant(
96+
new TemplateTypeMap([]),
97+
null,
9498
$this->getParameters(),
9599
$this->isVariadic(),
96100
$this->getReturnType()
@@ -99,4 +103,39 @@ public function getVariants(): array
99103
}
100104
return $this->variants;
101105
}
106+
107+
public function isDeprecated(): TrinaryLogic
108+
{
109+
return TrinaryLogic::createNo();
110+
}
111+
112+
public function isFinal(): TrinaryLogic
113+
{
114+
return TrinaryLogic::createNo();
115+
}
116+
117+
public function getDeprecatedDescription(): ?string
118+
{
119+
return null;
120+
}
121+
122+
public function hasSideEffects(): TrinaryLogic
123+
{
124+
return TrinaryLogic::createNo();
125+
}
126+
127+
public function getThrowType(): ?Type
128+
{
129+
return null;
130+
}
131+
132+
public function isInternal(): TrinaryLogic
133+
{
134+
return TrinaryLogic::createNo();
135+
}
136+
137+
public function getDocComment(): ?string
138+
{
139+
return null;
140+
}
102141
}

0 commit comments

Comments
 (0)