Skip to content

Commit 7a34a2c

Browse files
authored
Merge pull request #1250 from appwrite/fix-php-build-failing
fix: php build failing
2 parents 39ee7e0 + 3d17552 commit 7a34a2c

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

.github/workflows/sdk-build-validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ jobs:
173173
;;
174174
php)
175175
composer install
176+
find . -name "*.php" ! -path "./vendor/*" -exec php -l {} +
176177
;;
177178
python)
178179
pip install -e .

src/SDK/Language/PHP.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ public function getFiles(): array
172172
'destination' => 'composer.json',
173173
'template' => 'php/composer.json.twig',
174174
],
175+
[
176+
'scope' => 'default',
177+
'destination' => 'phpunit.xml',
178+
'template' => 'php/phpunit.xml.twig',
179+
],
175180
[
176181
'scope' => 'service',
177182
'destination' => 'docs/{{service.name | caseLower}}.md',

templates/php/composer.json.twig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"url": "{{ spec.contactURL }}",
88
"email": "{{ spec.contactEmail }}"
99
},
10+
"scripts": {
11+
"test": "vendor/bin/phpunit"
12+
},
1013
"autoload": {
1114
"psr-4": {
1215
"{{spec.title | caseUcfirst}}\\": "src/{{spec.title | caseUcfirst}}"
@@ -19,7 +22,7 @@
1922
},
2023
"require-dev": {
2124
"phpunit/phpunit": "^10",
22-
"mockery/mockery": "^1.6.6"
25+
"mockery/mockery": "^1.6.12"
2326
},
2427
"minimum-stability": "dev"
2528
}

templates/php/phpunit.xml.twig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
5+
bootstrap="vendor/autoload.php"
6+
cacheDirectory=".phpunit.cache"
7+
colors="true"
8+
displayDetailsOnIncompleteTests="true"
9+
displayDetailsOnSkippedTests="true"
10+
displayDetailsOnTestsThatTriggerDeprecations="true"
11+
displayDetailsOnTestsThatTriggerErrors="true"
12+
displayDetailsOnTestsThatTriggerNotices="true"
13+
displayDetailsOnTestsThatTriggerWarnings="true"
14+
failOnDeprecation="true"
15+
failOnEmptyTestSuite="true"
16+
failOnIncomplete="true"
17+
failOnRisky="true"
18+
failOnSkipped="true"
19+
failOnWarning="true"
20+
>
21+
<testsuites>
22+
<testsuite name="{{ spec.title | caseUcfirst }} SDK Test Suite">
23+
<directory>./tests/</directory>
24+
</testsuite>
25+
</testsuites>
26+
27+
<source>
28+
<include>
29+
<directory suffix=".php">./src/{{ spec.title | caseUcfirst }}</directory>
30+
</include>
31+
</source>
32+
</phpunit>

templates/php/src/Services/Service.php.twig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ class {{ service.name | caseUcfirst }} extends Service
3030
parent::__construct($client);
3131
}
3232
33+
{% set nonDeprecatedMethodNames = [] %}
3334
{% for method in service.methods %}
35+
{% if not method.deprecated %}
36+
{% set nonDeprecatedMethodNames = nonDeprecatedMethodNames|merge([method.name | caseCamel | lower]) %}
37+
{% endif %}
38+
{% endfor %}
39+
{% for method in service.methods %}
40+
{% set methodNameLower = method.name | caseCamel | lower %}
41+
{% if method.deprecated and methodNameLower in nonDeprecatedMethodNames %}
42+
{# Skip deprecated methods that have namespace collisions with non-deprecated methods #}
43+
{% else %}
3444
{% set deprecated_message = '' %}
3545
/**
3646
{% if method.description %}
@@ -72,6 +82,7 @@ class {{ service.name | caseUcfirst }} extends Service
7282
}
7383
{%~ if not loop.last %}
7484
85+
{%~ endif %}
7586
{%~ endif %}
7687
{%~ endfor %}
7788
}

templates/php/tests/Services/ServiceTest.php.twig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ final class {{service.name | caseUcfirst}}Test extends TestCase {
1616
$this->{{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($this->client);
1717
}
1818
19+
{% set nonDeprecatedMethodNames = [] %}
1920
{% for method in service.methods %}
21+
{% if not method.deprecated %}
22+
{% set nonDeprecatedMethodNames = nonDeprecatedMethodNames|merge([method.name | caseCamel | lower]) %}
23+
{% endif %}
24+
{% endfor %}
25+
{% for method in service.methods %}
26+
{% set methodNameLower = method.name | caseCamel | lower %}
27+
{% if method.deprecated and methodNameLower in nonDeprecatedMethodNames %}
28+
{# Skip deprecated methods that have namespace collisions with non-deprecated methods #}
29+
{% else %}
2030
public function testMethod{{method.name | caseUcfirst}}(): void {
2131
{%~ if method.responseModel and method.responseModel != 'any' ~%}
2232
$data = array(
@@ -40,5 +50,6 @@ final class {{service.name | caseUcfirst}}Test extends TestCase {
4050
$this->assertSame($data, $response);
4151
}
4252
53+
{% endif %}
4354
{% endfor %}
4455
}

0 commit comments

Comments
 (0)