Skip to content

Adds enum unit tests #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Unit Tests

on:
push:
branches:
- trunk
- 'feature/**'
- 'release/**'
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test.yml'
- '**.php'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
pull_request:
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test.yml'
- '**.php'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
types:
- opened
- reopened
- synchronize

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4', '8.0', '8.4']

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php-version }}-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run unit tests
run: composer phpunit
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ vendor/
CLAUDE.md
.cursor/
GEMINI.md

############
## PHPUnit
############

.phpunit.cache/
27 changes: 27 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true"
colors="true">
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/unit</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
17 changes: 17 additions & 0 deletions tests/mocks/Enums/InvalidNameTestEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace WordPress\AiClient\Tests\mocks\Enums;

use WordPress\AiClient\Common\AbstractEnum;

/**
* Invalid test enum with lowercase constant name.
*/
class InvalidNameTestEnum extends AbstractEnum
{
public const VALID_NAME = 'valid';
// phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
public const invalid_name = 'invalid'; // This should cause an exception
}
16 changes: 16 additions & 0 deletions tests/mocks/Enums/InvalidTypeTestEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace WordPress\AiClient\Tests\mocks\Enums;

use WordPress\AiClient\Common\AbstractEnum;

/**
* Invalid test enum with float value.
*/
class InvalidTypeTestEnum extends AbstractEnum
{
public const VALID_VALUE = 'valid';
public const INT_VALUE = 42; // This should cause an exception
}
21 changes: 21 additions & 0 deletions tests/mocks/Enums/ValidTestEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace WordPress\AiClient\Tests\mocks\Enums;

use WordPress\AiClient\Common\AbstractEnum;

/**
* Valid test enum for testing AbstractEnum functionality.
*
* @method static self firstName() Creates an instance for FIRST_NAME.
* @method static self lastName() Creates an instance for LAST_NAME.
* @method bool isFirstName() Checks if the value is FIRST_NAME.
* @method bool isLastName() Checks if the value is LAST_NAME.
*/
class ValidTestEnum extends AbstractEnum
{
public const FIRST_NAME = 'first';
public const LAST_NAME = 'last';
}
Loading