├── .gitattributes ├── .gitignore ├── .php_cs ├── .scrutinizer.yml ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src └── Michalmanko │ └── Holiday │ ├── Exception │ ├── InvalidArgumentException.php │ └── UnexpectedValueException.php │ ├── Holiday.php │ ├── HolidayFactory.php │ └── Provider │ ├── AbstractProvider.php │ ├── Denmark.php │ ├── Exception │ ├── InvalidArgumentException.php │ └── UnexpectedValueException.php │ └── Poland.php └── tests └── Michalmanko └── Holiday └── Test ├── Exception ├── InvalidArgumentExceptionTest.php └── UnexpectedValueExceptionTest.php ├── HolidayFactoryTest.php ├── HolidayTest.php └── Provider ├── AbstractProviderTest.php ├── AbstractTestProvider.php ├── DenmarkTest.php ├── Exception ├── InvalidArgumentExceptionTest.php └── UnexpectedValueExceptionTest.php ├── NotProvider.php ├── PolandTest.php └── Provider.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Definitively text files 2 | *.php text eol=lf 3 | *.yml text eol=lf 4 | *.xml text eol=lf 5 | *.xml.dist text eol=lf 6 | *.twig text eol=lf 7 | *.md text eol=lf 8 | *.html text eol=lf 9 | *.js text eol=lf 10 | *.css text eol=lf 11 | *.scss text eol=lf 12 | *.json text eol=lf 13 | *.txt text eol=lf 14 | *.php_cs text eol=lf 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Composer ### 2 | 3 | /composer.phar 4 | /composer.lock 5 | /vendor/ 6 | /bin/ 7 | 8 | 9 | ### App ### 10 | 11 | # Build 12 | /build/* 13 | !build/.gitkeep 14 | 15 | # PHPUnit 16 | /phpunit.xml 17 | 18 | ### Windows ### 19 | 20 | # Windows image file caches 21 | Thumbs.db 22 | ehthumbs.db 23 | 24 | # Folder config file 25 | Desktop.ini 26 | 27 | # Recycle Bin used on file shares 28 | $RECYCLE.BIN/ 29 | 30 | # Windows Installer files 31 | *.cab 32 | *.msi 33 | *.msm 34 | *.msp 35 | 36 | # Windows shortcuts 37 | *.lnk 38 | 39 | 40 | ### Linux ### 41 | 42 | *~ 43 | 44 | # KDE directory preferences 45 | .directory 46 | 47 | # Linux trash folder which might appear on any partition or disk 48 | .Trash-* 49 | 50 | 51 | ### OSX ### 52 | 53 | .DS_Store 54 | .AppleDouble 55 | .LSOverride 56 | 57 | # Icon must end with two \r 58 | Icon 59 | 60 | # Thumbnails 61 | ._* 62 | 63 | # Files that might appear in the root of a volume 64 | .DocumentRevisions-V100 65 | .fseventsd 66 | .Spotlight-V100 67 | .TemporaryItems 68 | .Trashes 69 | .VolumeIcon.icns 70 | 71 | # Directories potentially created on remote AFP share 72 | .AppleDB 73 | .AppleDesktop 74 | Network Trash Folder 75 | Temporary Items 76 | .apdisk 77 | 78 | 79 | ### NetBeans ### 80 | 81 | /nbproject/ 82 | /build/ 83 | /nbbuild/ 84 | /dist/ 85 | /nbdist/ 86 | /nbactions.xml 87 | /nb-configuration.xml 88 | /.nb-gradle/ 89 | 90 | 91 | ### Vim ### 92 | 93 | [._]*.s[a-w][a-z] 94 | [._]s[a-w][a-z] 95 | *.un~ 96 | Session.vim 97 | .netrwhist 98 | *~ 99 | 100 | 101 | ### SublimeText ### 102 | 103 | # cache files for sublime text 104 | *.tmlanguage.cache 105 | *.tmPreferences.cache 106 | *.stTheme.cache 107 | 108 | # workspace files are user-specific 109 | *.sublime-workspace 110 | 111 | # project files 112 | *.sublime-project 113 | # sftp configuration file 114 | /sftp-config.json 115 | 116 | ### Eclipse ### 117 | 118 | *.pydevproject 119 | /.metadata 120 | /.gradle 121 | /tmp/ 122 | *.tmp 123 | *.bak 124 | *.swp 125 | *~.nib 126 | local.properties 127 | /.settings/ 128 | .loadpath 129 | 130 | # Eclipse Core 131 | /.project 132 | 133 | # External tool builders 134 | /.externalToolBuilders/ 135 | 136 | # Locally stored "Eclipse launch configurations" 137 | *.launch 138 | 139 | # CDT-specific 140 | .cproject 141 | 142 | # JDT-specific (Eclipse Java Development Tools) 143 | .classpath 144 | 145 | # PDT-specific 146 | .buildpath 147 | 148 | # sbteclipse plugin 149 | .target 150 | 151 | # TeXlipse plugin 152 | .texlipse 153 | 154 | ### Intellij ### 155 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 156 | 157 | *.iml 158 | 159 | ## Directory-based project format: 160 | .idea/ 161 | 162 | ## File-based project format: 163 | *.ipr 164 | *.iws 165 | 166 | ## Plugin-specific files: 167 | 168 | # IntelliJ 169 | /out/ 170 | 171 | # mpeltonen/sbt-idea plugin 172 | .idea_modules/ 173 | 174 | # JIRA plugin 175 | atlassian-ide-plugin.xml 176 | 177 | # Crashlytics plugin (for Android Studio and IntelliJ) 178 | com_crashlytics_export_strings.xml 179 | crashlytics.properties 180 | crashlytics-build.properties -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | use Symfony\CS\Config\Config; 13 | use Symfony\CS\Finder\DefaultFinder; 14 | use Symfony\CS\Fixer\Contrib\HeaderCommentFixer; 15 | use Symfony\CS\FixerInterface; 16 | 17 | $header = <<<'EOF' 18 | This file is part of the Holiday Library. 19 | 20 | (c) Michał Mańko 21 | 22 | For the full copyright and license information, please view the LICENSE.md 23 | file that was distributed with this source code. 24 | EOF; 25 | HeaderCommentFixer::setHeader($header); 26 | 27 | $finder = DefaultFinder::create() 28 | ->in(array( 29 | __DIR__ . '/src', 30 | __DIR__ . '/tests', 31 | )); 32 | 33 | return Config::create() 34 | ->level(FixerInterface::NONE_LEVEL) 35 | ->fixers(array( 36 | 'psr0', 37 | 'encoding', 38 | 'short_tag', 39 | 'braces', 40 | 'elseif', 41 | 'eof_ending', 42 | 'function_call_space', 43 | 'function_declaration', 44 | 'indentation', 45 | 'line_after_namespace', 46 | 'linefeed', 47 | 'lowercase_constants', 48 | 'lowercase_keywords', 49 | 'method_argument_space', 50 | 'multiple_use', 51 | 'parenthesis', 52 | 'php_closing_tag', 53 | 'single_line_after_imports', 54 | 'trailing_spaces', 55 | 'visibility', 56 | 'concat_without_spaces', 57 | 'double_arrow_multiline_whitespaces', 58 | 'duplicate_semicolon', 59 | 'empty_return', 60 | 'extra_empty_lines', 61 | 'include', 62 | 'join_function', 63 | 'multiline_array_trailing_comma', 64 | 'namespace_no_leading_whitespace', 65 | 'new_with_braces', 66 | 'no_blank_lines_after_class_opening', 67 | 'no_empty_lines_after_phpdocs', 68 | 'object_operator', 69 | 'operators_spaces', 70 | 'phpdoc_indent', 71 | 'phpdoc_no_empty_return', 72 | 'phpdoc_no_package', 73 | 'phpdoc_params', 74 | 'phpdoc_scalar', 75 | 'phpdoc_separation', 76 | 'phpdoc_short_description', 77 | 'phpdoc_to_comment', 78 | 'phpdoc_trim', 79 | 'phpdoc_type_to_var', 80 | 'phpdoc_var_without_name', 81 | 'remove_leading_slash_use', 82 | 'remove_lines_between_uses', 83 | 'return', 84 | 'self_accessor', 85 | 'single_array_no_trailing_comma', 86 | 'single_blank_line_before_namespace', 87 | 'single_quote', 88 | 'spaces_before_semicolon', 89 | 'spaces_cast', 90 | 'standardize_not_equal', 91 | 'ternary_spaces', 92 | 'trim_array_spaces', 93 | 'unary_operators_spaces', 94 | 'unused_use', 95 | 'whitespacy_lines', 96 | 'align_double_arrow', 97 | 'align_equals', 98 | 'concat_with_spaces', 99 | 'header_comment', 100 | 'multiline_spaces_before_semicolon', 101 | 'no_blank_lines_before_namespace', 102 | 'ordered_use', 103 | 'phpdoc_order', 104 | 'long_array_syntax', 105 | 'header_comment', 106 | )) 107 | ->finder($finder); 108 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | before_commands: 2 | - composer install --dev --no-interaction 3 | tools: 4 | php_sim: true 5 | php_analyzer: 6 | enabled: true 7 | filter: 8 | excluded_paths: 9 | - './bin/*' 10 | - './vendor/*' 11 | - './build/*' 12 | php_code_sniffer: 13 | config: 14 | standard: "PSR2" 15 | filter: 16 | paths: 17 | - './src/*' 18 | - './tests/*' 19 | php_cpd: 20 | enabled: true 21 | excluded_dirs: 22 | - ./bin 23 | - ./vendor 24 | - ./build 25 | php_pdepend: 26 | enabled: true 27 | excluded_dirs: 28 | - ./bin 29 | - ./vendor 30 | - ./build 31 | php_loc: 32 | enabled: true 33 | excluded_dirs: 34 | - ./bin 35 | - ./vendor 36 | - ./build 37 | php_mess_detector: 38 | enabled: true 39 | config: 40 | rulesets: 41 | - cleancode 42 | - codesize 43 | - unusedcode 44 | - naming 45 | - design 46 | - controversial 47 | filter: 48 | excluded_paths: 49 | - './bin/*' 50 | - './vendor/*' 51 | - './build/*' 52 | build: 53 | environment: 54 | php: '5.6.0' 55 | tests: 56 | override: 57 | - 58 | command: './bin/phpunit -c ./phpunit.xml.dist --coverage-clover=./build/logs/clover.xml' 59 | coverage: 60 | file: './build/logs/clover.xml' 61 | format: 'php-clover' 62 | checks: 63 | php: 64 | code_rating: true 65 | duplication: true 66 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - "5.6" 5 | - "5.5" 6 | - "5.4" 7 | - "5.3" 8 | 9 | script: 10 | - bin/phpunit -c phpunit.xml.dist 11 | 12 | install: 13 | - composer install --dev --no-interaction 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | 1.1.0 5 | ---------- 6 | + 100% Code Coverage 7 | 8 | 1.0.0 9 | ---------- 10 | + upgrade phpunit to version 4.6 11 | + upgrade php-cs-fixer to version 1.8 12 | + moving tests from ./src to ./tests 13 | + start supporting PHP 7 14 | 15 | 0.2.0 16 | ---------- 17 | + Danish Holidays (thanks to @lsv) 18 | + PHP-CS-Fixer configuration 19 | + Travis-CI configuration fixed 20 | + Tests moved into namespace \Michalmanko\Holiday\Test 21 | + Files formatting improved 22 | + Scrutinizer configuration 23 | 24 | 0.1.1 25 | ---------- 26 | + Travis-CI configuration 27 | 28 | 0.1.0 29 | ---------- 30 | + First release 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributions are welcome! 2 | 3 | ## Quick guide: 4 | 5 | * [Fork the repo on GitHub](https://github.com/michalmanko/php-library-holiday/fork). 6 | * Install dependencies: `composer install`. 7 | * Create branch, e.g. feature-foo or bugfix-bar. 8 | * Make changes. 9 | * If you are adding functionality or fixing a bug - add a test! 10 | * Fix project: `php vendor/bin/php-cs-fixer fix`. 11 | * Check if tests pass: `vendor/bin/phpunit`. 12 | 13 | ## Opening a pull request 14 | 15 | You can do some things to increase the chance that your pull request is accepted the first time: 16 | 17 | * Submit one pull request per fix or feature. 18 | * If your changes are not up to date - rebase your branch on master. 19 | * Follow the conventions used in the project. 20 | * Remember about tests and documentation. 21 | * Don't bump version. 22 | 23 | ## Project's standards: 24 | 25 | * [PSR-0: Autoloading Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) 26 | * [PSR-1: Basic Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) 27 | * [PSR-2: Coding Style Guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) 28 | * [PSR-4: Autoloader](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md) 29 | * [Symfony Coding Standards](http://symfony.com/doc/current/contributing/code/standards.html) 30 | * Keep the order of class elements: static properties, instance properties, constructor (or setUp for PHPUnit), destructor (or tearDown for PHPUnit), static methods, instance methods, magic static methods, magic instance methods. 31 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Michał Mańko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Michalmanko/Holiday 2 | [![Build Status](https://travis-ci.org/michalmanko/php-library-holiday.svg?branch=master)](https://travis-ci.org/michalmanko/php-library-holiday) 3 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/michalmanko/php-library-holiday/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/michalmanko/php-library-holiday/?branch=master) 4 | [![Code Coverage](https://scrutinizer-ci.com/g/michalmanko/php-library-holiday/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/michalmanko/php-library-holiday/?branch=master) 5 | [![Dependency Status](https://www.versioneye.com/user/projects/5560cab5366466001f0c0000/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5560cab5366466001f0c0000) 6 | 7 | [![Latest Stable Version](https://poser.pugx.org/michalmanko/php-library-holiday/v/stable.svg)](https://packagist.org/packages/michalmanko/php-library-holiday) 8 | [![Latest Unstable Version](https://poser.pugx.org/michalmanko/php-library-holiday/v/unstable.svg)](https://packagist.org/packages/michalmanko/php-library-holiday) 9 | 10 | [![License](https://poser.pugx.org/michalmanko/php-library-holiday/license.svg)](https://packagist.org/packages/michalmanko/php-library-holiday) 11 | [![Total Downloads](https://poser.pugx.org/michalmanko/php-library-holiday/downloads.svg)](https://packagist.org/packages/michalmanko/php-library-holiday) 12 | [![Monthly Downloads](https://poser.pugx.org/michalmanko/php-library-holiday/d/monthly.png)](https://packagist.org/packages/michalmanko/php-library-holiday) 13 | 14 | Michalmanko/Holiday is a small library to check if a specified date is a holiday in a specific country. 15 | 16 | ## Requirements 17 | Michalmanko/Holiday requires PHP 5.3.23 or later. 18 | 19 | ## Installation 20 | 21 | ### Composer 22 | The easiest way to install this library is through [composer](http://getcomposer.org/). Just add the following lines to your **composer.json** file: 23 | 24 | ```json 25 | { 26 | "require": { 27 | "michalmanko/php-library-holiday": "~1.1.0" 28 | } 29 | } 30 | ``` 31 | 32 | ### Manually 33 | Another way would be to download this library and configure the autoloading yourself. This library relies on a [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md) compatible autoloader for automatic class loading. 34 | 35 | ## Usage 36 | 37 | ## Get a provider 38 | 39 | ```php 40 | $providerByIso = \Michalmanko\Holiday\HolidayFactory::createProvider('PL'); 41 | $providerByCountry = \Michalmanko\Holiday\HolidayFactory::createProvider('Poland'); 42 | $providerByClassName = \Michalmanko\Holiday\HolidayFactory::createProvider('\\Michalmanko\\Holiday\\Provider\\Poland'); 43 | ``` 44 | 45 | You can select provider by two-letter [ISO-3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country codes, country name or just a class name. 46 | 47 | ## Check holidays 48 | 49 | To check for holidays just create the provider for specific country and call the `getHolidays` method. 50 | 51 | ```php 52 | $provider = \Michalmanko\Holiday\HolidayFactory::createProvider('PL'); 53 | $holidays = $provider->getHolidays(new \DateTime('2014-01-01')); 54 | ``` 55 | 56 | If you just need to know if there is a holiday on your date or time period there are `isHoliday` and `hasHolidays` methods, too. 57 | 58 | If you need to know all holidays for a specific country you can call the `getHolidaysByYear` method. 59 | 60 | ## License 61 | Michalmanko\Holiday is licensed under the MIT License, see the [`LICENSE.md`](LICENSE.md) file for more details. 62 | 63 | ## Changelog 64 | See the [`CHANGELOG.md`](CHANGELOG.md) file for more details. 65 | 66 | ## Contributing 67 | Michalmanko/Holiday is open source. Everyone is more than welcome to [`contribute`](CONTRIBUTING.md) more of them. If you use this library it would be great to get some support for currently not implemented countries which you are familiar with. Pull requests will be reviewed and merged fast. 68 | 69 | To create a new Provider please see the [`\Michalmanko\Holiday\Provider\Poland`](src/Michalmanko/Holiday/Provider/Poland.php) class as an example. 70 | 71 | ## Running Tests 72 | Run a `php composer install` command in the base directory to install the `phpunit` dependency. After that you can simply call `vendor/bin/phpunit -c phpunit.xml.dist` to run the test suite. 73 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "michalmanko/php-library-holiday", 3 | "version": "1.1.0", 4 | "description": "A library to calculate holidays", 5 | "keywords": ["holiday", "polish holidays", "danish holidays"], 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [{ 9 | "name": "Michał Mańko", 10 | "email": "github@michalmanko.com" 11 | }], 12 | "autoload": { 13 | "psr-4": { 14 | "Michalmanko\\Holiday\\": "src/Michalmanko/Holiday/", 15 | "Michalmanko\\Holiday\\Test\\": "tests/Michalmanko/Holiday/Test/" 16 | } 17 | }, 18 | "require": { 19 | "php": ">=5.3.23" 20 | }, 21 | "require-dev": { 22 | "phpunit/phpunit": "~4.6.0", 23 | "johnkary/phpunit-speedtrap": "1.0.*@dev", 24 | "fabpot/php-cs-fixer": "~1.8.0" 25 | }, 26 | "config": { 27 | "bin-dir": "bin" 28 | }, 29 | "extra": { 30 | "branch-alias": { 31 | "dev-master": "1.1.x-dev" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | ./tests/Michalmanko/Holiday 13 | 14 | 15 | 16 | 17 | 18 | ./src 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 500 28 | 29 | 30 | 10 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/Exception/InvalidArgumentException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Exception; 13 | 14 | /** 15 | * Exception thrown if an argument does not match with the expected value. 16 | * 17 | * @author Michał Mańko 18 | */ 19 | class InvalidArgumentException extends \InvalidArgumentException 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/Exception/UnexpectedValueException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Exception; 13 | 14 | /** 15 | * Exception thrown if a value does not match with a set of values. 16 | * 17 | * @author Michał Mańko 18 | */ 19 | class UnexpectedValueException extends \UnexpectedValueException 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/Holiday.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday; 13 | 14 | use DateTime; 15 | use DateTimeZone; 16 | 17 | /** 18 | * Holiday class. 19 | * 20 | * @author Michał Mańko 21 | */ 22 | class Holiday extends DateTime 23 | { 24 | /** 25 | * Holiday type - Holiday. 26 | */ 27 | const TYPE_HOLIDAY = 'holiday'; 28 | 29 | /** 30 | * Holiday type - School Holiday. 31 | */ 32 | const TYPE_SCHOOL_HOLIDAY = 'school'; 33 | 34 | /** 35 | * Holiday type - notable. 36 | */ 37 | const TYPE_NOTABLE = 'notable'; 38 | 39 | /** 40 | * Holiday type. 41 | * 42 | * @var string 43 | */ 44 | private $type; 45 | 46 | /** 47 | * Holiday name. 48 | * 49 | * @var string 50 | */ 51 | private $name; 52 | 53 | /** 54 | * Creates a new Holiday. 55 | * 56 | * @param string $name Name 57 | * @param mixed $time Time 58 | * @param null|DateTimeZone $timezone (optional) Timezone 59 | * @param null|string $type (optional) Type 60 | */ 61 | public function __construct( 62 | $name, 63 | $time, 64 | DateTimeZone $timezone = null, 65 | $type = self::TYPE_HOLIDAY 66 | ) { 67 | if ($time instanceof DateTime) { 68 | $time = $time->format('Y-m-d H:i:s'); 69 | } 70 | parent::__construct($time, $timezone); 71 | 72 | $this->setName($name); 73 | $this->setType($type); 74 | } 75 | 76 | /** 77 | * Returns the holiday name. 78 | * 79 | * @return string 80 | */ 81 | public function getName() 82 | { 83 | return $this->name; 84 | } 85 | 86 | /** 87 | * Sets the holiday name. 88 | * 89 | * @param string $name 90 | * 91 | * @return Holiday 92 | */ 93 | public function setName($name) 94 | { 95 | $this->name = $name; 96 | 97 | return $this; 98 | } 99 | 100 | /** 101 | * Returns the holiday type. 102 | * 103 | * @return string 104 | */ 105 | public function getType() 106 | { 107 | return $this->type; 108 | } 109 | 110 | /** 111 | * Sets the holiday type. 112 | * 113 | * @param string $type 114 | * 115 | * @return Holiday 116 | */ 117 | public function setType($type) 118 | { 119 | $this->type = $type; 120 | 121 | return $this; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/HolidayFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday; 13 | 14 | use DateTimeZone; 15 | use Michalmanko\Holiday\Exception\InvalidArgumentException; 16 | 17 | /** 18 | * Holiday providers factory. 19 | * 20 | * Declared abstract, as we have no need for instantiation. 21 | * 22 | * @author Michał Mańko 23 | */ 24 | abstract class HolidayFactory 25 | { 26 | /** 27 | * Registered providers. 28 | * 29 | * @var array 30 | */ 31 | protected static $providers = array( 32 | 'PL' => 'Poland', 33 | 'DK' => 'Denmark', 34 | ); 35 | 36 | /** 37 | * Returns array with registered providers. 38 | * 39 | * @return array 40 | */ 41 | public static function getProviders() 42 | { 43 | return static::$providers; 44 | } 45 | 46 | /** 47 | * Registers a holidays provider class. 48 | * 49 | * @param string $countryCode Country code 50 | * @param string $providerClassName Provider class name 51 | */ 52 | public static function registerProvider($countryCode, $providerClassName) 53 | { 54 | $countryCode = strtoupper($countryCode); 55 | $providerClassName = (string) $providerClassName; 56 | 57 | static::$providers[$countryCode] = $providerClassName; 58 | } 59 | 60 | /** 61 | * Unregisters a holidays provider class. 62 | * 63 | * @param string $providerClassName Country code of the provider or the provider class name 64 | * 65 | * @return bool 66 | */ 67 | public static function unregisterProvider($providerClassName) 68 | { 69 | if (array_key_exists(strtoupper($providerClassName), static::$providers)) { 70 | unset(static::$providers[strtoupper($providerClassName)]); 71 | 72 | return true; 73 | } 74 | 75 | $index = array_search((string) $providerClassName, static::$providers, true); 76 | if ($index !== false) { 77 | unset(static::$providers[$index]); 78 | 79 | return true; 80 | } 81 | 82 | return false; 83 | } 84 | 85 | /** 86 | * Creates a holidays provider based on $countryCode code. 87 | * 88 | * @param string $countryCode ISO Country Code, County Name or provider class name 89 | * @param null|DateTimeZone $timezone (optional) Time zone 90 | * 91 | * @throws InvalidArgumentException 92 | * 93 | * @return Provider\AbstractProvider 94 | */ 95 | public static function createProvider($countryCode, DateTimeZone $timezone = null) 96 | { 97 | // Use the supplied provider class 98 | if (substr($countryCode, 0, 1) == '\\') { 99 | $className = $countryCode; 100 | } elseif (array_key_exists(strtoupper($countryCode), static::$providers)) { 101 | $countryCode = strtoupper($countryCode); 102 | if (substr(static::$providers[$countryCode], 0, 1) == '\\') { 103 | $className = static::$providers[$countryCode]; 104 | } else { 105 | $className = '\\' . __NAMESPACE__ . '\\Provider\\' 106 | . static::$providers[$countryCode]; 107 | } 108 | } else { 109 | $className = '\\' . __NAMESPACE__ . '\\Provider\\' . $countryCode; 110 | } 111 | 112 | if (!class_exists($className)) { 113 | throw new InvalidArgumentException(sprintf( 114 | 'Cannot find Holiday provider class "%s"', 115 | $className 116 | )); 117 | } 118 | 119 | $provider = new $className($timezone); 120 | 121 | if (!$provider instanceof Provider\AbstractProvider) { 122 | throw new InvalidArgumentException(sprintf( 123 | 'Class "%s" must be an instance of ' 124 | . '\\Michalmanko\\Holiday\\Provider\\AbstractProvider', 125 | $className 126 | )); 127 | } 128 | 129 | return $provider; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/Provider/AbstractProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Provider; 13 | 14 | use ArrayObject; 15 | use DateTime; 16 | use DateTimeZone; 17 | use Michalmanko\Holiday\Holiday; 18 | use Michalmanko\Holiday\Provider\Exception\InvalidArgumentException; 19 | use Michalmanko\Holiday\Provider\Exception\UnexpectedValueException; 20 | 21 | /** 22 | * Abstract provider class. 23 | * 24 | * @author Michał Mańko 25 | */ 26 | abstract class AbstractProvider 27 | { 28 | /** 29 | * Timezone. 30 | * 31 | * @var DateTimeZone 32 | */ 33 | protected $timezone; 34 | 35 | /** 36 | * List of holidays by year. 37 | * 38 | * @var array 39 | */ 40 | private $holidays = array(); 41 | 42 | /** 43 | * @param null|DateTimeZone $timezone (optional) Timezone 44 | */ 45 | public function __construct(DateTimeZone $timezone = null) 46 | { 47 | $this->timezone = $timezone; 48 | } 49 | 50 | /** 51 | * Prepare the holidays in given year. 52 | * 53 | * @param int $year The year to prepare the holidays for 54 | * 55 | * @return array An array of holidays 56 | */ 57 | abstract protected function prepareHolidays($year); 58 | 59 | /** 60 | * Returns timezone. 61 | * 62 | * @return DateTimeZone 63 | */ 64 | public function getTimeZone() 65 | { 66 | return $this->timezone; 67 | } 68 | 69 | /** 70 | * Creates a holiday object based on current timezone. 71 | * 72 | * @param string $name Name 73 | * @param mixed $time Time 74 | * @param string $type Type 75 | * 76 | * @return Holiday 77 | */ 78 | public function createHoliday($name, $time, $type = Holiday::TYPE_HOLIDAY) 79 | { 80 | return new Holiday($name, $time, $this->getTimeZone(), $type); 81 | } 82 | 83 | /** 84 | * Provides a DateTime object that represents easter sunday for this year.
85 | * The time is always set to 00:00:00. 86 | * 87 | * @param int $year The year for which to calculcate the easter sunday date 88 | * 89 | * @throws InvalidArgumentException 90 | * 91 | * @return DateTime 92 | */ 93 | protected function getEaster($year) 94 | { 95 | $easter = new DateTime('now', $this->getTimeZone()); 96 | $easter->setDate($year, 3, 21); 97 | $easter->setTime(0, 0, 0); 98 | $easter->modify('+' . easter_days($year) . 'days'); 99 | 100 | return $easter; 101 | } 102 | 103 | /** 104 | * Prepare the holidays in given year based on {@see prepareHolidays()}. 105 | * 106 | * @param int $year 107 | * 108 | * @throws UnexpectedValueException 109 | */ 110 | private function prepareHolidaysByYear($year) 111 | { 112 | if (!isset($this->holidays[$year])) { 113 | $preparedHolidays = $this->prepareHolidays($year); 114 | if (is_object($preparedHolidays) && $preparedHolidays instanceof ArrayObject) { 115 | $preparedHolidays = $preparedHolidays->getArrayCopy(); 116 | } 117 | if (!is_array($preparedHolidays)) { 118 | throw new UnexpectedValueException(\sprintf( 119 | 'Method %s::prepareHolidays() must returns an array', 120 | get_class($this) 121 | )); 122 | } 123 | 124 | $this->holidays[$year] = $preparedHolidays; 125 | } 126 | } 127 | 128 | /** 129 | * Returns the holidays in given year. 130 | * 131 | * @param int $year The year to get the holidays for 132 | * @param null|string $type (optional) Holiday type 133 | * 134 | * @throws InvalidArgumentException 135 | * 136 | * @return array An array of Holidays 137 | */ 138 | public function getHolidaysByYear($year, $type = null) 139 | { 140 | $this->prepareHolidaysByYear($year); 141 | 142 | if (null === $type) { 143 | return $this->holidays[$year]; 144 | } 145 | 146 | // Note: array_filter preserves keys, so we use array_values to reset array keys 147 | return array_values(array_filter( 148 | $this->holidays[$year], 149 | function (Holiday $holiday) use ($type) { 150 | return $holiday->getType() === $type; 151 | } 152 | )); 153 | } 154 | 155 | /** 156 | * Returns all holidays in the given time period. 157 | * 158 | * @param DateTime $startDate The start date 159 | * @param mixed $endDateOrType (optional) The end date or holiday type 160 | * @param string $type (optional) Holiday type 161 | * 162 | * @return array 163 | */ 164 | public function getHolidays( 165 | DateTime $startDate, 166 | $endDateOrType = null, 167 | $type = null 168 | ) { 169 | $startDate = clone $startDate; 170 | $startDate->setTime(0, 0, 0); 171 | 172 | if ($endDateOrType !== null && !($endDateOrType instanceof DateTime)) { 173 | if ($type !== null) { 174 | throw new InvalidArgumentException( 175 | '$endDateOrType must be an instance of \DateTime' 176 | ); 177 | } 178 | $type = $endDateOrType; 179 | $endDateOrType = clone $startDate; 180 | } elseif ($endDateOrType === null) { 181 | $endDateOrType = clone $startDate; 182 | } else { 183 | $endDateOrType = clone $endDateOrType; 184 | } 185 | $endDateOrType->setTime(23, 59, 59); 186 | 187 | $startyear = (int) $startDate->format('Y'); 188 | $endyear = (int) $endDateOrType->format('Y'); 189 | $holidays = array(); 190 | for ($y = $startyear; $y <= $endyear; $y++) { 191 | $holidays = array_merge($holidays, $this->getHolidaysByYear($y, $type)); 192 | } 193 | 194 | // Note: array_filter preserves keys, so we use array_values to reset array keys 195 | return array_values(array_filter( 196 | $holidays, 197 | function (Holiday $holiday) use ($startDate, $endDateOrType) { 198 | return $holiday >= $startDate && $holiday <= $endDateOrType; 199 | } 200 | )); 201 | } 202 | 203 | /** 204 | * Returns true if any holiday exists in the given time period. 205 | * 206 | * @param DateTime $startDate The start date 207 | * @param null|DateTime $endDate (optional) The end date 208 | * @param null|string $type (optional) Holiday type 209 | * 210 | * @return bool 211 | */ 212 | public function hasHolidays( 213 | DateTime $startDate, 214 | DateTime $endDate, 215 | $type = null 216 | ) { 217 | return count($this->getHolidays($startDate, $endDate, $type)) > 0; 218 | } 219 | 220 | /** 221 | * Returns true if $date is a holiday. 222 | * 223 | * @param DateTime $date The date 224 | * @param null|string $type (optional) Holiday type 225 | * 226 | * @return bool 227 | */ 228 | public function isHoliday(DateTime $date, $type = null) 229 | { 230 | return count($this->getHolidays($date, null, $type)) > 0; 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/Provider/Denmark.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Provider; 13 | 14 | use ArrayObject; 15 | use Michalmanko\Holiday\Holiday; 16 | 17 | /** 18 | * Danish Holidays Provider. 19 | */ 20 | class Denmark extends AbstractProvider 21 | { 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | protected function prepareHolidays($year) 26 | { 27 | $data = new ArrayObject(); 28 | 29 | // New year's day 30 | $data->append($this->createHoliday( 31 | 'Nytårsdag', 32 | $year . '-01-01', 33 | Holiday::TYPE_HOLIDAY 34 | )); 35 | 36 | // Easter Sunday 37 | $easter = $this->createHoliday( 38 | 'Påskedag', 39 | $this->getEaster($year), 40 | Holiday::TYPE_HOLIDAY 41 | ); 42 | $data->append($easter); 43 | 44 | // Maundy Thursday 45 | $easterThursday = $this->createHoliday( 46 | 'Skærtorsdag', 47 | $easter, 48 | Holiday::TYPE_HOLIDAY 49 | ); 50 | $easterThursday->modify('-3 days'); 51 | $data->append($easterThursday); 52 | 53 | // Good Friday 54 | $easterFriday = $this->createHoliday( 55 | 'Langfredag', 56 | $easter, 57 | Holiday::TYPE_HOLIDAY 58 | ); 59 | $easterFriday->modify('-2 days'); 60 | $data->append($easterFriday); 61 | 62 | // Easter Monday 63 | $easterMonday = $this->createHoliday( 64 | '2. Påskedag', 65 | $easter, 66 | Holiday::TYPE_HOLIDAY 67 | ); 68 | $easterMonday->modify('+1 day'); 69 | $data->append($easterMonday); 70 | 71 | // Prayer day 72 | $prayerDay = $this->createHoliday( 73 | 'Store bededag', 74 | $easter, 75 | Holiday::TYPE_HOLIDAY 76 | ); 77 | $prayerDay->modify('+3 weeks +5 days'); 78 | $data->append($prayerDay); 79 | 80 | // Ascension Day 81 | $ascensionDay = $this->createHoliday( 82 | 'Kristi himmelfartsdag', 83 | $easter, 84 | Holiday::TYPE_HOLIDAY 85 | ); 86 | $ascensionDay->modify('+39 days'); 87 | $data->append($ascensionDay); 88 | 89 | // Pentecost day 90 | $pentecostDay = $this->createHoliday( 91 | 'Pinsedag', 92 | $easter, 93 | Holiday::TYPE_HOLIDAY 94 | ); 95 | $pentecostDay->modify('+49 days'); 96 | $data->append($pentecostDay); 97 | 98 | // 2. Pentecost day 99 | $pentecostDay2 = $this->createHoliday( 100 | '2. Pinsedag', 101 | $pentecostDay, 102 | Holiday::TYPE_HOLIDAY 103 | ); 104 | $pentecostDay2->modify('+1 day'); 105 | $data->append($pentecostDay2); 106 | 107 | // Constitution day 108 | $data->append($this->createHoliday( 109 | 'Grundlovsdag', 110 | $year . '-06-5', 111 | Holiday::TYPE_HOLIDAY 112 | )); 113 | 114 | // Christmas day 115 | $data->append($this->createHoliday( 116 | 'Juledag', 117 | $year . '-12-25', 118 | Holiday::TYPE_HOLIDAY 119 | )); 120 | 121 | // Boxing Day 122 | $data->append($this->createHoliday( 123 | '2. Juledag', 124 | $year . '-12-26', 125 | Holiday::TYPE_HOLIDAY 126 | )); 127 | 128 | return $data->getArrayCopy(); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/Provider/Exception/InvalidArgumentException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Provider\Exception; 13 | 14 | use Michalmanko\Holiday\Exception\InvalidArgumentException as ParentInvalidArgumentException; 15 | 16 | /** 17 | * Exception thrown if an argument does not match with the expected value. 18 | * 19 | * @author Michał Mańko 20 | */ 21 | class InvalidArgumentException extends ParentInvalidArgumentException 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/Provider/Exception/UnexpectedValueException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Provider\Exception; 13 | 14 | use Michalmanko\Holiday\Exception\UnexpectedValueException as ParentUnexpectedValueException; 15 | 16 | /** 17 | * Exception thrown if a value does not match with a set of values. 18 | * 19 | * @author Michał Mańko 20 | */ 21 | class UnexpectedValueException extends ParentUnexpectedValueException 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /src/Michalmanko/Holiday/Provider/Poland.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Provider; 13 | 14 | use ArrayObject; 15 | use Michalmanko\Holiday\Holiday; 16 | 17 | /** 18 | * Polish Holidays Provider. 19 | * 20 | * @author Michał Mańko 21 | */ 22 | class Poland extends AbstractProvider 23 | { 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | protected function prepareHolidays($year) 28 | { 29 | $data = new ArrayObject(); 30 | 31 | // Easter Sunday 32 | $easter = $this->createHoliday( 33 | 'Pierwszy dzień Wielkiej Nocy', 34 | $this->getEaster($year), 35 | Holiday::TYPE_HOLIDAY 36 | ); 37 | $data->append($easter); 38 | // Easter Monday 39 | $easterMonday = $this->createHoliday( 40 | 'Drugi dzień Wielkiej Nocy', 41 | $easter, 42 | Holiday::TYPE_HOLIDAY 43 | ); 44 | $easterMonday->modify('+1 day'); 45 | $data->append($easterMonday); 46 | // Pentecost Sunday 47 | $pentecost = $this->createHoliday( 48 | 'Zielone Świątki', 49 | $easter, 50 | Holiday::TYPE_HOLIDAY 51 | ); 52 | $pentecost->modify('+49 days'); 53 | $data->append($pentecost); 54 | // Corpus Christi 55 | $corpusChristi = $this->createHoliday( 56 | 'Boże Ciało', 57 | $easter, 58 | Holiday::TYPE_HOLIDAY 59 | ); 60 | $corpusChristi->modify('+60 days'); 61 | $data->append($corpusChristi); 62 | // New Year's Day 63 | $data->append($this->createHoliday( 64 | 'Nowy Rok', 65 | $year . '-01-01', 66 | Holiday::TYPE_HOLIDAY 67 | )); 68 | // Epiphany 69 | $data->append($this->createHoliday( 70 | 'Trzech króli', 71 | $year . '-01-06', 72 | Holiday::TYPE_HOLIDAY 73 | )); 74 | // Labour Day 75 | $data->append($this->createHoliday( 76 | 'Święto Pracy', 77 | $year . '-05-01', 78 | Holiday::TYPE_HOLIDAY 79 | )); 80 | // Constitution Day 81 | $data->append($this->createHoliday( 82 | 'Święto Konstytucji Trzeciego Maja', 83 | $year . '-05-03', 84 | Holiday::TYPE_HOLIDAY 85 | )); 86 | // Assumption of the Blessed Virgin Mary 87 | $data->append($this->createHoliday( 88 | 'Wniebowzięcie Najświętszej Maryi Panny', 89 | $year . '-08-15', 90 | Holiday::TYPE_HOLIDAY 91 | )); 92 | // All Saints' Day 93 | $data->append($this->createHoliday( 94 | 'Dzień Zmarłych', 95 | $year . '-11-01', 96 | Holiday::TYPE_HOLIDAY 97 | )); 98 | // Independence Day 99 | $data->append($this->createHoliday( 100 | 'Dzień Niepodległości', 101 | $year . '-11-11', 102 | Holiday::TYPE_HOLIDAY 103 | )); 104 | // Christmas Day 105 | $data->append($this->createHoliday( 106 | 'Boże Narodzenie', 107 | $year . '-12-25', 108 | Holiday::TYPE_HOLIDAY 109 | )); 110 | // Boxing Day 111 | $data->append($this->createHoliday( 112 | 'Drugi dzień Bożego Narodzenia', 113 | $year . '-12-26', 114 | Holiday::TYPE_HOLIDAY 115 | )); 116 | 117 | return $data->getArrayCopy(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Exception/InvalidArgumentExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Exception; 13 | 14 | use Michalmanko\Holiday\Exception\InvalidArgumentException; 15 | 16 | /** 17 | * @author Michał Mańko 18 | */ 19 | class InvalidArgumentExceptionTest extends \PHPUnit_Framework_TestCase 20 | { 21 | /** 22 | * @var InvalidArgumentException 23 | */ 24 | protected $object; 25 | 26 | protected function setUp() 27 | { 28 | $this->object = new InvalidArgumentException(); 29 | } 30 | 31 | public function testException() 32 | { 33 | $this->assertInstanceOf( 34 | '\\InvalidArgumentException', 35 | $this->object 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Exception/UnexpectedValueExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Exception; 13 | 14 | use Michalmanko\Holiday\Exception\UnexpectedValueException; 15 | 16 | /** 17 | * @author Michał Mańko 18 | */ 19 | class UnexpectedValueExceptionTest extends \PHPUnit_Framework_TestCase 20 | { 21 | /** 22 | * @var UnexpectedValueException 23 | */ 24 | protected $object; 25 | 26 | protected function setUp() 27 | { 28 | $this->object = new UnexpectedValueException(); 29 | } 30 | 31 | public function testException() 32 | { 33 | $this->assertInstanceOf( 34 | '\\UnexpectedValueException', 35 | $this->object 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/HolidayFactoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test; 13 | 14 | use Michalmanko\Holiday\HolidayFactory; 15 | use PHPUnit_Framework_TestCase; 16 | 17 | /** 18 | * @author Michał Mańko 19 | */ 20 | class HolidayFactoryTest extends PHPUnit_Framework_TestCase 21 | { 22 | public function testCreateProvider() 23 | { 24 | $provider = HolidayFactory::createProvider( 25 | '\\Michalmanko\\Holiday\\Test\\Provider\\Provider' 26 | ); 27 | 28 | $this->assertInstanceOf( 29 | '\\Michalmanko\\Holiday\\Provider\\AbstractProvider', 30 | $provider 31 | ); 32 | $this->assertInstanceOf( 33 | '\\Michalmanko\\Holiday\\Test\\Provider\\Provider', 34 | $provider 35 | ); 36 | 37 | HolidayFactory::registerProvider( 38 | 'Country', 39 | '\\Michalmanko\\Holiday\\Test\\Provider\\Provider' 40 | ); 41 | 42 | $provider2 = HolidayFactory::createProvider('Country'); 43 | 44 | $this->assertInstanceOf('\\Michalmanko\\Holiday\\Provider\\AbstractProvider', $provider2); 45 | $this->assertInstanceOf('\\Michalmanko\\Holiday\\Test\\Provider\\Provider', $provider2); 46 | 47 | $provider3 = HolidayFactory::createProvider('Poland'); 48 | 49 | $this->assertInstanceOf('\\Michalmanko\\Holiday\\Provider\\AbstractProvider', $provider3); 50 | $this->assertInstanceOf('\\Michalmanko\\Holiday\\Provider\\Poland', $provider3); 51 | } 52 | 53 | public function testProviderFactoryNotFound() 54 | { 55 | $this->setExpectedException( 56 | '\\Michalmanko\\Holiday\\Exception\\InvalidArgumentException', 57 | 'Cannot find Holiday provider class "\\Michalmanko\\Holiday\\FakeProvider\\Provider"' 58 | ); 59 | HolidayFactory::createProvider('\\Michalmanko\\Holiday\\FakeProvider\\Provider'); 60 | } 61 | 62 | public function testProviderFactoryNotFound2() 63 | { 64 | $this->setExpectedException( 65 | '\\Michalmanko\\Holiday\\Exception\\InvalidArgumentException', 66 | 'Cannot find Holiday provider class "\\Michalmanko\\Holiday\\Provider\\FakeProvider"' 67 | ); 68 | HolidayFactory::createProvider('FakeProvider'); 69 | } 70 | 71 | public function testProviderFactoryInvalidProvider() 72 | { 73 | $this->setExpectedException( 74 | '\\Michalmanko\\Holiday\\Exception\\InvalidArgumentException', 75 | 'Class "\\Michalmanko\\Holiday\\Test\\Provider\\NotProvider"' 76 | . ' must be an instance of \\Michalmanko\\Holiday\\Provider\\AbstractProvider' 77 | ); 78 | HolidayFactory::createProvider('\\Michalmanko\\Holiday\\Test\\Provider\\NotProvider'); 79 | } 80 | 81 | public function testProviderFactoryRegistry() 82 | { 83 | $this->assertInternalType('array', HolidayFactory::getProviders()); 84 | } 85 | 86 | public function testProviderFactoryRegistryRegister() 87 | { 88 | HolidayFactory::registerProvider('Test', 'TestProvider'); 89 | $this->assertArrayHasKey('TEST', HolidayFactory::getProviders()); 90 | } 91 | 92 | public function testProviderFactoryRegistryUnregister() 93 | { 94 | HolidayFactory::registerProvider('Test', 'TestProvider'); 95 | HolidayFactory::unregisterProvider('TEST'); 96 | 97 | $this->setExpectedException( 98 | '\\Michalmanko\\Holiday\\Exception\\InvalidArgumentException', 99 | 'Cannot find Holiday provider class "\\Michalmanko\\Holiday\\Provider\\TEST"' 100 | ); 101 | HolidayFactory::createProvider('TEST'); 102 | } 103 | 104 | public function testProviderFactoryRegistryUnregisterByName() 105 | { 106 | HolidayFactory::registerProvider('Test', 'TestProvider'); 107 | $this->assertTrue(HolidayFactory::unregisterProvider('Test')); 108 | } 109 | 110 | public function testProviderFactoryRegistryUnregisterByClassName() 111 | { 112 | HolidayFactory::registerProvider('Test', 'TestProvider'); 113 | $this->assertTrue(HolidayFactory::unregisterProvider('TestProvider')); 114 | } 115 | 116 | public function testProviderFactoryRegistryUnregisterByNameUnknown() 117 | { 118 | $this->assertFalse(HolidayFactory::unregisterProvider('Foo')); 119 | } 120 | 121 | public function testProviderFactoryRegistryRegisterByNamespace() 122 | { 123 | HolidayFactory::registerProvider( 124 | 'Provider', 125 | '\\Michalmanko\\Holiday\\Test\\Provider\\Provider' 126 | ); 127 | $provider = HolidayFactory::createProvider('Provider'); 128 | $this->assertInstanceOf('\\Michalmanko\\Holiday\\Provider\\AbstractProvider', $provider); 129 | } 130 | 131 | public function testProviderFactoryRegistryRegisterByNotInstanceOfAbstract() 132 | { 133 | $this->setExpectedException('\\Michalmanko\\Holiday\\Exception\\InvalidArgumentException'); 134 | HolidayFactory::registerProvider('NotProvider', '\\Michalmanko\\Holiday\\Test\\Provider\\'); 135 | HolidayFactory::createProvider('NotProvider'); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/HolidayTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test; 13 | 14 | use DateTime; 15 | use Michalmanko\Holiday\Holiday; 16 | use PHPUnit_Framework_TestCase; 17 | 18 | /** 19 | * @author Michał Mańko 20 | */ 21 | class HolidayTest extends PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @var Holiday 25 | */ 26 | protected $object; 27 | 28 | protected function setUp() 29 | { 30 | $this->object = new Holiday('name', '2015-01-01'); 31 | } 32 | 33 | public function testInstance() 34 | { 35 | $this->assertInstanceOf('\DateTime', $this->object); 36 | } 37 | 38 | public function testName() 39 | { 40 | $this->assertEquals('name', $this->object->getName()); 41 | 42 | $this->assertSame($this->object, $this->object->setName('newName')); 43 | 44 | $this->assertEquals('newName', $this->object->getName()); 45 | } 46 | 47 | public function testType() 48 | { 49 | $this->assertEquals(Holiday::TYPE_HOLIDAY, $this->object->getType()); 50 | 51 | $this->assertSame($this->object, $this->object->setType(Holiday::TYPE_SCHOOL_HOLIDAY)); 52 | 53 | $this->assertEquals(Holiday::TYPE_SCHOOL_HOLIDAY, $this->object->getType()); 54 | } 55 | 56 | public function testConstructDefaultValues() 57 | { 58 | $this->assertEquals(Holiday::TYPE_HOLIDAY, $this->object->getType()); 59 | 60 | $this->assertEquals( 61 | date_default_timezone_get(), 62 | $this->object->getTimezone()->getName() 63 | ); 64 | } 65 | 66 | public function testInvalidTimeInConstruct() 67 | { 68 | $this->setExpectedException( 69 | '\\Exception', 70 | 'DateTime::__construct(): Failed to parse time string (invalid-date) ' 71 | . 'at position 0 (i): The timezone could not be found in the database' 72 | ); 73 | new Holiday('name', 'invalid-date'); 74 | } 75 | 76 | public function testInvalidTimezoneInConstruct() 77 | { 78 | $this->setExpectedException( 79 | '\\PHPUnit_Framework_Error', 80 | 'Argument 3 passed to Michalmanko\Holiday\Holiday::__construct() ' 81 | . 'must be an instance of DateTimeZone, string given' 82 | ); 83 | new Holiday('name', '2015-01-01', 'timezone'); 84 | } 85 | 86 | public function testTimeAsDateTimeInConstruct() 87 | { 88 | $date = new DateTime('2015-01-01'); 89 | 90 | $holiday = new Holiday('name', $date); 91 | 92 | $this->assertEquals($date->getTimestamp(), $holiday->getTimestamp()); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Provider/AbstractProviderTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Provider; 13 | 14 | use ArrayObject; 15 | use DateTime; 16 | use DateTimeZone; 17 | use Michalmanko\Holiday\Holiday; 18 | use PHPUnit_Framework_MockObject_MockObject; 19 | use PHPUnit_Framework_TestCase; 20 | use ReflectionClass; 21 | 22 | /** 23 | * @author Michał Mańko 24 | */ 25 | class AbstractProviderTest extends PHPUnit_Framework_TestCase 26 | { 27 | /** 28 | * @var PHPUnit_Framework_MockObject_MockObject 29 | */ 30 | protected $object; 31 | 32 | protected $holiday1; 33 | 34 | protected $holiday2; 35 | 36 | protected $schoolHoliday1; 37 | 38 | protected $schoolHoliday2; 39 | 40 | public function setUp() 41 | { 42 | $this->holiday1 = $holiday1 = new Holiday( 43 | 'Holiday 1', 44 | '2015-01-01', 45 | null, 46 | Holiday::TYPE_HOLIDAY 47 | ); 48 | $this->holiday2 = $holiday2 = new Holiday( 49 | 'Holiday 2', 50 | '2015-01-10', 51 | null, 52 | Holiday::TYPE_HOLIDAY 53 | ); 54 | $this->schoolHoliday1 = $schoolHoliday1 = new Holiday( 55 | 'School Holiday 1', 56 | '2015-01-02', 57 | null, 58 | Holiday::TYPE_SCHOOL_HOLIDAY 59 | ); 60 | $this->schoolHoliday2 = $schoolHoliday2 = new Holiday( 61 | 'School Holiday 2', 62 | '2015-01-01', 63 | null, 64 | Holiday::TYPE_SCHOOL_HOLIDAY 65 | ); 66 | 67 | $this->object = $this->getMockForAbstractClass( 68 | '\\Michalmanko\\Holiday\\Provider\\AbstractProvider' 69 | ); 70 | $this->object->expects($this->any()) 71 | ->method('prepareHolidays') 72 | ->withAnyParameters() 73 | ->willReturnCallback(function () use ( 74 | $holiday1, 75 | $holiday2, 76 | $schoolHoliday1, 77 | $schoolHoliday2 78 | ) { 79 | $data = new ArrayObject(); 80 | 81 | $data->append($holiday1); 82 | $data->append($holiday2); 83 | $data->append($schoolHoliday1); 84 | $data->append($schoolHoliday2); 85 | 86 | return $data->getArrayCopy(); 87 | }); 88 | } 89 | 90 | public function testGetTimeZone() 91 | { 92 | $this->assertNull($this->object->getTimeZone()); 93 | 94 | $timezone = new DateTimeZone('Europe/London'); 95 | 96 | $mock = $this->getMockForAbstractClass( 97 | '\\Michalmanko\\Holiday\\Provider\\AbstractProvider', 98 | array($timezone) 99 | ); 100 | 101 | $this->assertSame($timezone, $mock->getTimeZone()); 102 | } 103 | 104 | public function testCreateHoliday() 105 | { 106 | $holiday = $this->object->createHoliday( 107 | 'holidayName', 108 | '2015-01-01' 109 | ); 110 | 111 | $this->assertInstanceOf( 112 | '\\Michalmanko\\Holiday\\Holiday', 113 | $holiday 114 | ); 115 | 116 | $this->assertEquals('holidayName', $holiday->getName()); 117 | 118 | $this->assertEquals('2015-01-01', $holiday->format('Y-m-d')); 119 | 120 | $this->assertEquals(date_default_timezone_get(), $holiday->getTimeZone()->getName()); 121 | 122 | $this->assertEquals(Holiday::TYPE_HOLIDAY, $holiday->getType()); 123 | } 124 | 125 | public function testCreateHolidayWithTimeZone() 126 | { 127 | $timezone = new DateTimeZone('Europe/London'); 128 | 129 | $mock = $this->getMockForAbstractClass( 130 | '\\Michalmanko\\Holiday\\Provider\\AbstractProvider', 131 | array($timezone) 132 | ); 133 | 134 | $holiday = $mock->createHoliday( 135 | 'holidayName', 136 | '2015-01-01' 137 | ); 138 | 139 | $this->assertEquals($timezone->getName(), $holiday->getTimeZone()->getName()); 140 | } 141 | 142 | public function testCreateHolidayWithType() 143 | { 144 | $holiday = $this->object->createHoliday( 145 | 'holidayName', 146 | '2015-01-01', 147 | Holiday::TYPE_SCHOOL_HOLIDAY 148 | ); 149 | 150 | $this->assertEquals(Holiday::TYPE_SCHOOL_HOLIDAY, $holiday->getType()); 151 | } 152 | 153 | public function testGetEaster() 154 | { 155 | $getEaster = self::getMethod('getEaster'); 156 | $easter = $getEaster->invokeArgs($this->object, array(2015)); 157 | 158 | $this->assertEquals('2015-04-05', $easter->format('Y-m-d')); 159 | } 160 | 161 | public function testGetHolidaysByYear() 162 | { 163 | $this->object->expects($this->once()) 164 | ->method('prepareHolidays') 165 | ->with(2015); 166 | 167 | $this->object->getHolidaysByYear(2015); 168 | $holidays = $this->object->getHolidaysByYear(2015); 169 | 170 | $this->assertSame( 171 | array( 172 | $this->holiday1, 173 | $this->holiday2, 174 | $this->schoolHoliday1, 175 | $this->schoolHoliday2, 176 | ), 177 | $holidays 178 | ); 179 | } 180 | 181 | public function testGetHolidaysByYearWithArrayObject() 182 | { 183 | $mock = $this->getMockForAbstractClass( 184 | '\\Michalmanko\\Holiday\\Provider\\AbstractProvider' 185 | ); 186 | $mock->expects($this->any()) 187 | ->method('prepareHolidays') 188 | ->withAnyParameters() 189 | ->willReturn(new ArrayObject()); 190 | 191 | $mock->getHolidaysByYear(2015); 192 | } 193 | 194 | public function testGetHolidaysByYearWithInvalidData() 195 | { 196 | $mock = $this->getMockForAbstractClass( 197 | '\\Michalmanko\\Holiday\\Provider\\AbstractProvider' 198 | ); 199 | $this->setExpectedException( 200 | '\\Michalmanko\\Holiday\\Provider\\Exception\\UnexpectedValueException', 201 | sprintf( 202 | 'Method %s::prepareHolidays() must returns an array', 203 | get_class($mock) 204 | ) 205 | ); 206 | $mock->expects($this->any()) 207 | ->method('prepareHolidays') 208 | ->withAnyParameters() 209 | ->willReturn('string'); 210 | 211 | $mock->getHolidaysByYear(2015); 212 | } 213 | 214 | public function testGetHolidaysByYearWithTypeFilter() 215 | { 216 | $holidays = $this->object->getHolidaysByYear(2015, Holiday::TYPE_SCHOOL_HOLIDAY); 217 | 218 | $this->assertSame( 219 | array( 220 | $this->schoolHoliday1, 221 | $this->schoolHoliday2, 222 | ), 223 | $holidays 224 | ); 225 | } 226 | 227 | public function testGetHolidays() 228 | { 229 | $date = new DateTime('2015-01-01 12:00:00'); 230 | $dateTimestamp = $date->getTimestamp(); 231 | 232 | $holidays = $this->object->getHolidays($date); 233 | 234 | $this->assertEquals($dateTimestamp, $date->getTimestamp()); 235 | 236 | $this->assertEquals( 237 | array( 238 | $this->holiday1, 239 | $this->schoolHoliday2, 240 | ), 241 | $holidays 242 | ); 243 | } 244 | 245 | public function testGetHolidaysWithType() 246 | { 247 | $date = new DateTime('2015-01-01 12:00:00'); 248 | 249 | $holidays = $this->object->getHolidays($date, Holiday::TYPE_SCHOOL_HOLIDAY); 250 | 251 | $this->assertEquals( 252 | array($this->schoolHoliday2), 253 | $holidays 254 | ); 255 | } 256 | 257 | public function testGetHolidaysWithEndDate() 258 | { 259 | $dateStart = new DateTime('2015-01-01 12:00:00'); 260 | $dateEnd = new DateTime('2015-01-01 14:00:00'); 261 | $dateEndTimestamp = $dateEnd->getTimestamp(); 262 | 263 | $holidays = $this->object->getHolidays($dateStart, $dateEnd); 264 | 265 | $this->assertEquals($dateEndTimestamp, $dateEnd->getTimestamp()); 266 | 267 | $this->assertEquals( 268 | array( 269 | $this->holiday1, 270 | $this->schoolHoliday2, 271 | ), 272 | $holidays 273 | ); 274 | } 275 | 276 | public function testGetHolidaysWithInvalidEndDate() 277 | { 278 | $dateStart = new DateTime('2015-01-01 12:00:00'); 279 | 280 | $this->setExpectedException( 281 | '\\Michalmanko\\Holiday\\Provider\\Exception\\InvalidArgumentException', 282 | '$endDateOrType must be an instance of \\DateTime' 283 | ); 284 | 285 | $this->object->getHolidays($dateStart, 'invalid-date', Holiday::TYPE_HOLIDAY); 286 | } 287 | 288 | public function testHasHolidays() 289 | { 290 | $this->assertTrue($this->object->hasHolidays( 291 | new DateTime('2015-01-01'), 292 | new DateTime('2015-01-02') 293 | )); 294 | 295 | $this->assertFalse($this->object->hasHolidays( 296 | new DateTime('2015-02-01'), 297 | new DateTime('2015-02-02') 298 | )); 299 | } 300 | 301 | public function testIsHoliday() 302 | { 303 | $this->assertTrue($this->object->isHoliday( 304 | new DateTime('2015-01-01') 305 | )); 306 | 307 | $this->assertFalse($this->object->isHoliday( 308 | new DateTime('2015-02-01') 309 | )); 310 | } 311 | 312 | protected static function getMethod($name) 313 | { 314 | $class = new ReflectionClass('\\Michalmanko\\Holiday\\Provider\\AbstractProvider'); 315 | $method = $class->getMethod($name); 316 | $method->setAccessible(true); 317 | 318 | return $method; 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Provider/AbstractTestProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Provider; 13 | 14 | use DateTime; 15 | use Michalmanko\Holiday\HolidayFactory; 16 | use Michalmanko\Holiday\Provider\AbstractProvider; 17 | use PHPUnit_Framework_TestCase; 18 | 19 | /** 20 | * Abstract provider test class. 21 | * 22 | * @author Michał Mańko 23 | */ 24 | abstract class AbstractTestProvider extends PHPUnit_Framework_TestCase 25 | { 26 | /** 27 | * @var AbstractProvider 28 | */ 29 | protected $provider; 30 | 31 | public function setUp() 32 | { 33 | $this->provider = HolidayFactory::createProvider($this->getProviderCountryCode()); 34 | } 35 | 36 | public function testIsProviderRegisteredInFactory() 37 | { 38 | $this->assertArraySubset( 39 | array($this->getProviderCountryCode() => $this->getProviderCountryName()), 40 | HolidayFactory::getProviders() 41 | ); 42 | } 43 | 44 | public function testIsCorrectProvider() 45 | { 46 | $this->assertInstanceOf($this->getProviderInstanceOf(), $this->provider); 47 | } 48 | 49 | /** 50 | * @dataProvider dataProvider 51 | */ 52 | public function testDates($name, $type, $dates) 53 | { 54 | foreach ($dates as $date) { 55 | $holidays = $this->provider->getHolidays(new DateTime($date)); 56 | $this->assertNotCount( 57 | 0, 58 | $holidays, 59 | sprintf('There is no holiday on %s', $date) 60 | ); 61 | $holiday = array_shift($holidays); 62 | $this->assertEquals( 63 | $name, 64 | $holiday->getName(), 65 | sprintf('Holiday on %s is not %s', $date, $name) 66 | ); 67 | $this->assertEquals( 68 | $type, 69 | $holiday->getType(), 70 | sprintf('Holiday on %s is not type of %s', $date, $type) 71 | ); 72 | } 73 | } 74 | 75 | abstract public function dataProvider(); 76 | 77 | abstract public function getProviderCountryCode(); 78 | 79 | abstract public function getProviderCountryName(); 80 | 81 | abstract public function getProviderInstanceOf(); 82 | } 83 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Provider/DenmarkTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Provider; 13 | 14 | use Michalmanko\Holiday\Holiday; 15 | 16 | /** 17 | * 18 | */ 19 | class DenmarkTest extends AbstractTestProvider 20 | { 21 | public function getProviderCountryCode() 22 | { 23 | return 'DK'; 24 | } 25 | 26 | public function getProviderCountryName() 27 | { 28 | return 'Denmark'; 29 | } 30 | 31 | public function getProviderInstanceOf() 32 | { 33 | return '\\Michalmanko\\Holiday\\Provider\\Denmark'; 34 | } 35 | 36 | public function dataProvider() 37 | { 38 | return array( 39 | array('Nytårsdag', Holiday::TYPE_HOLIDAY, array('2015-01-01', '2020-01-01')), 40 | array('Skærtorsdag', Holiday::TYPE_HOLIDAY, array('2015-04-02', '2020-04-09')), 41 | array('Langfredag', Holiday::TYPE_HOLIDAY, array('2015-04-03', '2020-04-10')), 42 | array('Påskedag', Holiday::TYPE_HOLIDAY, array('2015-04-05', '2020-04-12')), 43 | array('2. Påskedag', Holiday::TYPE_HOLIDAY, array('2015-04-06', '2020-04-13')), 44 | array( 45 | 'Store bededag', 46 | Holiday::TYPE_HOLIDAY, 47 | array('2015-05-01', '2020-05-08', '2025-05-16'), 48 | ), 49 | array( 50 | 'Kristi himmelfartsdag', 51 | Holiday::TYPE_HOLIDAY, 52 | array('2015-05-14', '2020-05-21', '2025-05-29'), 53 | ), 54 | array( 55 | 'Pinsedag', 56 | Holiday::TYPE_HOLIDAY, 57 | array('2015-05-24', '2020-05-31', '2025-06-08'), 58 | ), 59 | array( 60 | '2. Pinsedag', 61 | Holiday::TYPE_HOLIDAY, 62 | array('2015-05-25', '2020-06-01', '2025-06-09'), 63 | ), 64 | array('Grundlovsdag', Holiday::TYPE_HOLIDAY, array('2015-06-05', '2016-06-05')), 65 | array('Juledag', Holiday::TYPE_HOLIDAY, array('2015-12-25', '2020-12-25')), 66 | array('2. Juledag', Holiday::TYPE_HOLIDAY, array('2015-12-26', '2020-12-26')), 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Provider/Exception/InvalidArgumentExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Provider\Exception; 13 | 14 | use Michalmanko\Holiday\Provider\Exception\InvalidArgumentException; 15 | 16 | /** 17 | * @author Michał Mańko 18 | */ 19 | class InvalidArgumentExceptionTest extends \PHPUnit_Framework_TestCase 20 | { 21 | /** 22 | * @var InvalidArgumentException 23 | */ 24 | protected $object; 25 | 26 | protected function setUp() 27 | { 28 | $this->object = new InvalidArgumentException(); 29 | } 30 | 31 | public function testException() 32 | { 33 | $this->assertInstanceOf( 34 | '\\Michalmanko\\Holiday\\Exception\\InvalidArgumentException', 35 | $this->object 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Provider/Exception/UnexpectedValueExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Provider\Exception; 13 | 14 | use Michalmanko\Holiday\Provider\Exception\UnexpectedValueException; 15 | 16 | /** 17 | * @author Michał Mańko 18 | */ 19 | class UnexpectedValueExceptionTest extends \PHPUnit_Framework_TestCase 20 | { 21 | /** 22 | * @var UnexpectedValueException 23 | */ 24 | protected $object; 25 | 26 | protected function setUp() 27 | { 28 | $this->object = new UnexpectedValueException(); 29 | } 30 | 31 | public function testException() 32 | { 33 | $this->assertInstanceOf( 34 | '\\Michalmanko\\Holiday\\Exception\\UnexpectedValueException', 35 | $this->object 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Provider/NotProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Provider; 13 | 14 | /** 15 | * @author Michał Mańko 16 | */ 17 | class NotProvider 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Provider/PolandTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Provider; 13 | 14 | use Michalmanko\Holiday\Holiday; 15 | 16 | /** 17 | * @author Michał Mańko 18 | */ 19 | class PolandTest extends AbstractTestProvider 20 | { 21 | public function getProviderCountryCode() 22 | { 23 | return 'PL'; 24 | } 25 | 26 | public function getProviderCountryName() 27 | { 28 | return 'Poland'; 29 | } 30 | 31 | public function getProviderInstanceOf() 32 | { 33 | return '\\Michalmanko\\Holiday\\Provider\\Poland'; 34 | } 35 | 36 | public function dataProvider() 37 | { 38 | return array( 39 | array('Nowy Rok', Holiday::TYPE_HOLIDAY, array('2015-01-01', '2020-01-01')), 40 | array( 41 | 'Pierwszy dzień Wielkiej Nocy', 42 | Holiday::TYPE_HOLIDAY, 43 | array('2015-04-05', '2020-04-12'), 44 | ), 45 | array( 46 | 'Drugi dzień Wielkiej Nocy', 47 | Holiday::TYPE_HOLIDAY, 48 | array('2015-04-06', '2020-04-13'), 49 | ), 50 | array('Zielone Świątki', Holiday::TYPE_HOLIDAY, array('2015-05-24')), 51 | array('Boże Ciało', Holiday::TYPE_HOLIDAY, array('2015-06-04', '2020-06-11')), 52 | array('Trzech króli', Holiday::TYPE_HOLIDAY, array('2015-01-06', '2020-01-06')), 53 | array('Święto Pracy', Holiday::TYPE_HOLIDAY, array('2015-05-01', '2020-05-01')), 54 | array( 55 | 'Święto Konstytucji Trzeciego Maja', 56 | Holiday::TYPE_HOLIDAY, 57 | array('2015-05-03', '2020-05-03'), 58 | ), 59 | array( 60 | 'Wniebowzięcie Najświętszej Maryi Panny', 61 | Holiday::TYPE_HOLIDAY, 62 | array('2015-08-15', '2020-08-15'), 63 | ), 64 | array('Dzień Zmarłych', Holiday::TYPE_HOLIDAY, array('2015-11-01', '2020-11-01')), 65 | array('Dzień Niepodległości', Holiday::TYPE_HOLIDAY, array('2015-11-11', '2020-11-11')), 66 | array('Boże Narodzenie', Holiday::TYPE_HOLIDAY, array('2015-12-25', '2020-12-25')), 67 | array( 68 | 'Drugi dzień Bożego Narodzenia', 69 | Holiday::TYPE_HOLIDAY, 70 | array('2015-12-26', '2020-12-26'), 71 | ), 72 | ); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/Michalmanko/Holiday/Test/Provider/Provider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE.md 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Michalmanko\Holiday\Test\Provider; 13 | 14 | use Michalmanko\Holiday\Provider\AbstractProvider; 15 | 16 | /* 17 | * @author Michał Mańko 18 | */ 19 | class Provider extends AbstractProvider 20 | { 21 | protected function prepareHolidays($year) 22 | { 23 | } 24 | } 25 | --------------------------------------------------------------------------------