This commit is contained in:
Victor Westerlund 2023-10-06 13:31:29 +00:00 committed by GitHub
commit 8351969941
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1758 additions and 1 deletions

19
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,19 @@
name: PHP xEnum CI
run-name: PHP xEnum CI
on: [push, pull_request]
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
uses: php-actions/composer@v6
- name: Run PHPUnit Tests
uses: php-actions/phpunit@v3
with:
bootstrap: vendor/autoload.php
configuration: test/phpunit.xml

View file

@ -15,5 +15,8 @@
"victorwesterlund\\": "src/"
}
},
"require": {}
"require": {},
"require-dev": {
"phpunit/phpunit": "^10"
}
}

1672
composer.lock generated Normal file

File diff suppressed because it is too large Load diff

18
test/phpunit.xml Normal file
View file

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">../../src</directory>
</include>
<report>
<html outputDirectory="./_coverage" lowUpperBound="35" highLowerBound="70"/>
<text outputFile="php://stdout" showUncoveredFiles="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="main">
<directory suffix="Test.php">.</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>

45
test/xEnumTest.php Normal file
View file

@ -0,0 +1,45 @@
<?php
use \PHPUnit\Framework\TestCase;
use \victorwesterlund\xEnum;
require_once dirname(__DIR__) . "/src/xEnum.php";
enum Test: string {
use xEnum;
case TEST1 = "test1";
case TEST2 = "test2";
case TEST3 = "test3";
}
final class xEnumTest extends TestCase {
const VALUES = [
"TEST1" => "test1",
"TEST2" => "test2",
"TEST3" => "test3"
];
public function testFromName(): void {
$test = Test::TEST1;
$this->assertSame($test, Test::fromName($test->name));
}
public function testTryFromName(): void {
$test = Test::TEST1;
$this->assertSame($test, Test::tryFromName($test->name));
}
public function testTryFromNameInvalid(): void {
$this->assertSame(null, Test::tryFromName("INVALID"));
}
public function testNames(): void {
$this->assertSame(array_keys(self::VALUES), Test::names());
}
public function testValues(): void {
$this->assertSame(array_values(self::VALUES), Test::values());
}
}