-
Notifications
You must be signed in to change notification settings - Fork 3
Adding PHPUnit [Not Ready] #3
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
Open
gogl92
wants to merge
5
commits into
ShibuyaKosuke:main
Choose a base branch
from
inquid:Phpunit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
53f3846
:white_check_mark: Adding phpunit
contactinquid c6bf359
:white_check_mark: Adding phpunit
contactinquid 51421bd
Create php.yml
gogl92 fd2a7fa
Merge pull request #1 from inquid/Phpunit
gogl92 6065bfa
Merge branch 'ShibuyaKosuke:main' into Phpunit
gogl92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: PHP Composer | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- 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-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-php- | ||
|
||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress | ||
|
||
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" | ||
# Docs: https://getcomposer.org/doc/articles/scripts.md | ||
|
||
- name: Run test suite | ||
run: composer test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache"> | ||
<coverage/> | ||
<testsuites> | ||
<testsuite name="Application Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShibuyaKosuke\LaravelYasumi\Tests; | ||
|
||
use Illuminate\Config\Repository; | ||
use Illuminate\Support\Carbon; | ||
use ReflectionException; | ||
use ShibuyaKosuke\LaravelYasumi\Holiday; | ||
use Yasumi\Exception\MissingTranslationException; | ||
|
||
class HolidayTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider holidayDataProvider | ||
* @return array[] | ||
*/ | ||
public static function holidayDataProvider() | ||
{ | ||
return [ | ||
[ 'Japan', 'ja_JP', '2020-01-01', '元日' ], | ||
[ 'Japan', 'ja_JP', '2020-01-13', '成人の日' ], | ||
[ 'Japan', 'ja_JP', '2020-02-11', '建国記念の日' ], | ||
[ 'Japan', 'ja_JP', '2020-02-23', '天皇誕生日' ], | ||
[ 'Japan', 'ja_JP', '2020-02-24', '振替休日 (天皇誕生日)' ], | ||
[ 'Japan', 'ja_JP', '2020-03-20', '春分の日' ], | ||
[ 'Japan', 'ja_JP', '2020-04-29', '昭和の日' ], | ||
[ 'Japan', 'ja_JP', '2020-05-03', '憲法記念日' ], | ||
[ 'Japan', 'ja_JP', '2020-05-04', 'みどりの日' ], | ||
[ 'Japan', 'ja_JP', '2020-05-05', 'こどもの日' ], | ||
[ 'Japan', 'ja_JP', '2020-05-06', '振替休日 (憲法記念日)' ], | ||
[ 'Japan', 'ja_JP', '2020-07-23', '海の日' ], | ||
[ 'Japan', 'ja_JP', '2020-07-24', 'スポーツの日' ], | ||
[ 'Japan', 'ja_JP', '2020-08-10', '山の日' ], | ||
[ 'Japan', 'ja_JP', '2020-09-21', '敬老の日' ], | ||
[ 'Japan', 'ja_JP', '2020-09-22', '秋分の日' ], | ||
[ 'Japan', 'ja_JP', '2020-11-03', '文化の日' ], | ||
[ 'Japan', 'ja_JP', '2020-11-23', '勤労感謝の日' ], | ||
[ 'Japan', 'ja_JP', '2020-11-23', '勤労感謝の日' ], | ||
[ 'Spain', 'es', '2021-01-01', 'Año Nuevo' ], | ||
[ 'USA', 'en_US', '2020-01-01', 'New Year’s Day' ], | ||
[ 'USA', 'en_US', '2020-01-20', 'Dr. Martin Luther King Jr’s Birthday' ], | ||
[ 'USA', 'en_US', '2020-02-17', 'Washington’s Birthday' ], | ||
[ 'USA', 'en_US', '2020-05-25', 'Memorial Day' ], | ||
[ 'USA', 'en_US', '2020-07-03', 'Independence Day observed' ], | ||
[ 'USA', 'en_US', '2020-09-07', 'Labor Day' ], | ||
[ 'USA', 'en_US', '2020-10-12', 'Columbus Day' ], | ||
[ 'USA', 'en_US', '2020-11-11', 'Veterans Day' ], | ||
[ 'USA', 'en_US', '2020-11-26', 'Thanksgiving Day' ], | ||
[ 'USA', 'en_US', '2020-12-25', 'Christmas' ], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $country | ||
* @param string $locale | ||
* @param string $date | ||
* @param string $expectedHoliday | ||
* @throws ReflectionException | ||
* @throws MissingTranslationException | ||
* @dataProvider holidayDataProvider | ||
*/ | ||
public function testCanGetHolidays($country, $locale, $date, $expectedHoliday): void | ||
{ | ||
$config = new Repository([ | ||
'yasumi' => [ | ||
'country' => $country, | ||
'locale' => $locale, | ||
], | ||
]); | ||
$holiday = new Holiday($config); | ||
$newYear = Carbon::make($date); | ||
$holidayResult = $holiday->get($newYear); | ||
$this->assertEquals($expectedHoliday, $holidayResult); | ||
} | ||
|
||
/** | ||
* Test isHoliday method. | ||
* | ||
* @throws ReflectionException | ||
* @throws MissingTranslationException | ||
* @dataProvider holidayDataProvider | ||
*/ | ||
public function testIsHoliday($country, $locale, $date, $expectedHoliday): void | ||
{ | ||
$config = new Repository([ | ||
'yasumi' => [ | ||
'country' => $country, | ||
'locale' => $locale, | ||
], | ||
]); | ||
$holiday = new Holiday($config); | ||
$newYear = Carbon::make($date); | ||
$this->assertTrue($holiday->isHoliday($newYear)); | ||
} | ||
|
||
/** | ||
* Test isBeforeHoliday method. | ||
* | ||
* @throws ReflectionException | ||
* @throws MissingTranslationException | ||
* @dataProvider holidayDataProvider | ||
*/ | ||
public function testIsDayBeforeHoliday($country, $locale, $date, $expectedHoliday): void | ||
{ | ||
$config = new Repository([ | ||
'yasumi' => [ | ||
'country' => $country, | ||
'locale' => $locale, | ||
], | ||
]); | ||
$holiday = new Holiday($config); | ||
$newYear = Carbon::make($date)->subDay(); | ||
$this->assertTrue($holiday->isDayBeforeHoliday($newYear)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShibuyaKosuke\LaravelYasumi\Tests; | ||
|
||
abstract class TestCase extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't make it work so I created a new workflow file.