Skip to content

Commit

Permalink
Test in GitLab CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed May 10, 2022
1 parent 811b9cb commit 0691584
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/*.phar
.idea/
/release-changelog*.md
/local-php-security-checker
25 changes: 23 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
stages:
- test
- build
- review
- cleanup
Expand All @@ -11,9 +12,27 @@ variables:
PF_PARENT_ENV: 3.x
PF_NO_CLONE_PARENT: 1 # CLI environments are stateless, so no need for data cloning

quick-tests:
stage: test
image: php:7.4-cli
before_script:
- apt-get update
- apt-get install zip unzip git lsof -y
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php
- mkdir -p /cache/composer/bin && chmod +x composer.phar && mv composer.phar /cache/composer/bin/composer
script:
- export PATH="/cache/composer/bin:$PATH"
# No Composer scripts, because Box isn't needed (and Box needs PHP 7.4).
- composer install --no-interaction --no-scripts
- scripts/test/security.sh
- scripts/test/unit.sh
- scripts/test/offline.sh

build:
stage: build
needs: []
needs:
- quick-tests
image: php:7.4-cli
before_script:
- apt-get update
Expand All @@ -39,7 +58,8 @@ push-review-env:
image: pjcdawkins/platformsh-cli
script:
- bash scripts/gitlab-ci/push-platform.sh
needs: []
needs:
- quick-tests
stage: review
artifacts:
reports:
Expand All @@ -59,6 +79,7 @@ cleanup-review-envs:
needs:
- push-review-env
stage: cleanup
allow_failure: true

delete-review-env:
image: pjcdawkins/platformsh-cli
Expand Down
4 changes: 2 additions & 2 deletions dist/dev-build-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
$pharDate = false;
}

if ($config->has('application.github_repo')) {
if ($config->getWithDefault('application.github_repo', '')) {
$sourceLink = 'https://github.com/' . $config->get('application.github_repo');
$sourceLinkSpecific = $sourceLink;
if ($branch) {
Expand Down Expand Up @@ -114,7 +114,7 @@
<?php if ($sourceLink): ?>
<h1><a href="<?= htmlspecialchars($sourceLink) ?>"><?= htmlspecialchars($appName) ?></a></h1>
<?php else: ?>
<h1>><?= htmlspecialchars($appName) ?></h1>
<h1><?= htmlspecialchars($appName) ?></h1>
<?php endif; ?>
<h2>Development build</h2>

Expand Down
16 changes: 14 additions & 2 deletions scripts/test/security.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/usr/bin/env bash
# Tests the composer.lock file against the SensioLabs security checker.
# Tests the composer.lock file using fabpot/local-php-security-checker.
# This must be run from the repository root.

curl -H 'Accept: text/plain' https://security.symfony.com/check_lock -F lock=@./composer.lock
cmd=local-php-security-checker

if [ -f ./local-php-security-checker ]; then
cmd=./local-php-security-checker
elif ! command -v local-php-security-checker >/dev/null; then
url=https://github.com/fabpot/local-php-security-checker/releases/download/v1.2.0/local-php-security-checker_1.2.0_linux_amd64
echo >&2 "Downloading security checker from $url"
curl -sfSL "$url" > ./local-php-security-checker
chmod +x ./local-php-security-checker
cmd=./local-php-security-checker
fi

$cmd
35 changes: 24 additions & 11 deletions tests/Service/FilesystemServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,32 @@ public function testSymlinkAll()

public function testCanWrite()
{
\umask(0002);

$testDir = $this->createTempSubDir();
touch($testDir . '/test-file');
$this->assertTrue($this->fs->canWrite($testDir . '/test-file'));
if (touch($testDir . '/test-file')) {
$this->assertTrue($this->fs->canWrite($testDir . '/test-file'));
} else {
$this->markTestIncomplete('Failed to create file: ' . $testDir . '/test-file');
}

chmod($testDir . '/test-file', 0500);
$this->assertFalse($this->fs->canWrite($testDir . '/test-file'));
mkdir($testDir . '/test-dir', 0700);
$this->assertTrue($this->fs->canWrite($testDir . '/test-dir'));
$this->assertTrue($this->fs->canWrite($testDir . '/test-dir/1'));
$this->assertTrue($this->fs->canWrite($testDir . '/test-dir/1/2/3'));
mkdir($testDir . '/test-ro-dir', 0500);
$this->assertFalse(is_writable($testDir . '/test-ro-dir'));
$this->assertFalse($this->fs->canWrite($testDir . '/test-ro-dir'));
$this->assertFalse($this->fs->canWrite($testDir . '/test-ro-dir/1'));
$this->assertEquals(\is_writable($testDir . '/test-file'), $this->fs->canWrite($testDir . '/test-file'));

if (mkdir($testDir . '/test-dir', 0700)) {
$this->assertTrue($this->fs->canWrite($testDir . '/test-dir'));
$this->assertTrue($this->fs->canWrite($testDir . '/test-dir/1'));
$this->assertTrue($this->fs->canWrite($testDir . '/test-dir/1/2/3'));
} else {
$this->markTestIncomplete('Failed to create directory: ' . $testDir . '/test-dir');
}

if (mkdir($testDir . '/test-ro-dir', 0500)) {
$this->assertEquals(is_writable($testDir . '/test-ro-dir'), $this->fs->canWrite($testDir . '/test-ro-dir'));
$this->assertEquals(is_writable($testDir . '/test-ro-dir'), $this->fs->canWrite($testDir . '/test-ro-dir/1'));
} else {
$this->markTestIncomplete('Failed to create directory: ' . $testDir . '/test-ro-dir');
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
*/

require __DIR__ . '/../vendor/autoload.php';

error_reporting(E_ALL);
ini_set('display_errors', 'stderr');

0 comments on commit 0691584

Please sign in to comment.