Skip to content

Commit

Permalink
Add an integration test for the composer install
Browse files Browse the repository at this point in the history
  • Loading branch information
acoulton committed Dec 17, 2024
1 parent ed57181 commit a3f957b
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:

jobs:

integration-test-composer:
runs-on: ubuntu-latest

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2

- name: Checkout
uses: actions/checkout@v4

# Github doesn't seem to like a working-directory arg for a custom action
# and I ideally want to test this works as expected in the root
- name: Copy test files to root
run: cp test/cached-composer-install/composer.* .

- name: Install with dev dependencies
uses: ./cached-composer-install

- name: Check all packages installed
env:
EXPECT_DEV_PACKAGES: installed
run: php test/cached-composer-install/check-installed.php
32 changes: 32 additions & 0 deletions test/cached-composer-install/check-installed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

$expect_installed = match (getenv('EXPECT_DEV_PACKAGES')) {
'installed' => [
'psr/log' => true,
'psr/cache' => true,
],
'not-installed' => [
'psr/log' => true,
'psr/cache' => false,
],
default => throw new InvalidArgumentException('Define EXPECT_DEV_PACKAGES as installed|not-installed')
};

require_once './vendor/autoload.php';

$actual = [
'psr/log' => interface_exists(\Psr\Log\LoggerInterface::class),
'psr/cache' => interface_exists(\Psr\Cache\CacheItemPoolInterface::class),
];

if ($actual === $expect_installed) {
echo "Correct packages were installed: ";
print_r($actual);
exit;
}

print "Installed packages: ";
print_r($actual);
print "Did not match expected: ";
print_r($expect_installed);
exit(1);
8 changes: 8 additions & 0 deletions test/cached-composer-install/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": {
"psr/log": "^3.0"
},
"require-dev": {
"psr/cache": "^3.0"
}
}
119 changes: 119 additions & 0 deletions test/cached-composer-install/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3f957b

Please sign in to comment.