diff --git a/.gitattributes b/.gitattributes index 12bbbb7..9c83161 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,5 @@ /.gitattributes export-ignore /.gitignore export-ignore -/.travis.yml export-ignore /phpunit.xml export-ignore /tests export-ignore diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..a83d708 --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,23 @@ +name: Check & fix styling + +on: [push] + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP CS Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php-cs-fixer.dist.php --allow-risky=yes + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Fix styling diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..097491e --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,37 @@ +name: Tests + +on: [push, pull_request] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest, windows-latest] + php: [8.0] + stability: [prefer-lowest, prefer-stable] + + name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 988e8e0..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Tests - -on: - push: - branches: - - "**" - pull_request: - types: [ready_for_review, synchronize, opened] - -jobs: - php-tests: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - php: [7.2, 7.3, 7.4] - dependency-version: [prefer-lowest, prefer-stable] - os: [ubuntu-latest] - - name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} - env: - extensions: mbstring, intl - key: v1 - - steps: - - name: Checkout the code - uses: actions/checkout@v2 - - - name: Setup cache environment - id: cache-env - uses: shivammathur/cache-extensions@v1 - with: - php-version: ${{ matrix.php }} - extensions: ${{ env.extensions }} - key: ${{ env.key }} - - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ${{ steps.cache-env.outputs.dir }} - key: ${{ steps.cache-env.outputs.key }} - restore-keys: ${{ steps.cache-env.outputs.key }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extension: ${{ env.extensions }} - coverage: xdebug - - - name: Install dependencies - run: | - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - - - name: Execute tests - run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 20e9158..2aa1559 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build/ vendor/ .DS_Store +.php-cs-fixer.cache .phpunit.result.cache composer.phar composer.lock diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 0000000..61f225d --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.0.11","version":"3.2.1","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"class_definition":{"space_before_parenthesis":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/Calendar.php":4069419489,"src\/Day.php":3566524330,"src\/Week.php":1355338800,"src\/AbstractCarbonWrapper.php":499610566,"tests\/Calendar\/WeekTest.php":1555848260,"tests\/Calendar\/CalendarTest.php":1852566807,"tests\/Calendar\/DayTest.php":4247321876}} \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..8d8a790 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,40 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR12' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'no_unused_imports' => true, + 'not_operator_with_successor_space' => true, + 'trailing_comma_in_multiline' => true, + 'phpdoc_scalar' => true, + 'unary_operator_spaces' => true, + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + ], + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_var_without_name' => true, + 'class_attributes_separation' => [ + 'elements' => [ + 'method' => 'one', + ], + ], + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'keep_multiple_spaces_after_comma' => true, + ], + 'single_trait_insert_per_statement' => true, + ]) + ->setFinder($finder); diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 364c818..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: php - -php: - - 7.2 - - 7.3 - -# This triggers builds to run on the new TravisCI infrastructure. -# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ -sudo: false - -## Cache composer -cache: - directories: - - $HOME/.composer/cache - -env: - global: - - CC_TEST_REPORTER_ID=9d275dce9d3faf1c92b7b4bc27d6395b282b8a516fffffea6896933c104ea56b - matrix: - - COMPOSER_FLAGS="--prefer-lowest" - - COMPOSER_FLAGS="" - -before_script: - - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - - chmod +x ./cc-test-reporter - - ./cc-test-reporter before-build - - travis_retry composer self-update - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist - -script: - - vendor/bin/phpunit - -after_script: - - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi diff --git a/README.md b/README.md index eef445c..684d963 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ -[![Code Climate](https://codeclimate.com/github/kmdwebdesigns/calendar.png)](https://codeclimate.com/github/kmdwebdesigns/calendar) -[![SensioLabsInsight](https://insight.sensiolabs.com/projects/004f9246-a92c-479a-a0e0-4564fe43eaa5/mini.png)](https://insight.sensiolabs.com/projects/004f9246-a92c-479a-a0e0-4564fe43eaa5) + +[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/kmdwebdesigns/calendar/run-tests?label=tests)](https://github.com/kmdwebdesigns/calendar/actions?query=workflow%3ATests+branch%3Amaster) +[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/kmdwebdesigns/calendar/Check%20&%20fix%20styling?label=code%20style)](https://github.com/kmdwebdesigns/calendar/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amaster) + # Calendar diff --git a/composer.json b/composer.json index 660624f..a9d6a5d 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,12 @@ } ], "require": { - "php": ">=7.2", + "php": "^8.0", "nesbot/carbon": "^2.24" }, "require-dev": { - "phpunit/phpunit": "^8.0" + "friendsofphp/php-cs-fixer": "^3.0", + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-4": { @@ -28,5 +29,15 @@ "psr-4": { "Tests\\": "tests" } - } + }, + "scripts": { + "test": "vendor/bin/phpunit", + "test-coverage": "vendor/bin/phpunit --coverage", + "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/phpunit.xml b/phpunit.xml index f60d84e..00557b0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,31 +1,39 @@ - + tests - - - src - - + + + ./src + + + + + + + - - - - - + diff --git a/src/Calendar.php b/src/Calendar.php index 6bd47c4..6b17d6b 100644 --- a/src/Calendar.php +++ b/src/Calendar.php @@ -12,7 +12,7 @@ class Calendar * The number of weeks a calendar month displays * (This includes blank days from other months) */ - const WEEKS_IN_MONTH = 6; + public const WEEKS_IN_MONTH = 6; /** * @var int diff --git a/tests/Calendar/WeekTest.php b/tests/Calendar/WeekTest.php index 63ddf5c..1f199fa 100644 --- a/tests/Calendar/WeekTest.php +++ b/tests/Calendar/WeekTest.php @@ -9,21 +9,21 @@ class WeekTest extends TestCase { - function testSetsTheCurrentMonthToTheStartDatesMonthIfNoneIsSpecified() + public function testSetsTheCurrentMonthToTheStartDatesMonthIfNoneIsSpecified() { $start = new Day(2014, 7, 20); $week = new Week($start, null, CarbonInterface::SUNDAY); $this->assertSame(7, $week->getCurrentMonth()); } - function testDetectsIfTheStartingDayIsNotTheFirstDayOfTheWeek() + public function testDetectsIfTheStartingDayIsNotTheFirstDayOfTheWeek() { $start = new Day(2014, 7, 1); $week = new Week($start, null, CarbonInterface::SUNDAY); $this->assertSame('2014-06-29', $week->getStartDate()->toDateString()); } - function testSetsTheCurrentMonthToTheSpecifiedValue() + public function testSetsTheCurrentMonthToTheSpecifiedValue() { $start = new Day(2014, 7, 20); $currentMonth = 8; @@ -32,7 +32,7 @@ function testSetsTheCurrentMonthToTheSpecifiedValue() $this->assertSame(8, $week->getCurrentMonth()); } - function testReturnsTheDaysThatBelongToANormalWeek() + public function testReturnsTheDaysThatBelongToANormalWeek() { $start = new Day(2014, 7, 20); $week = new Week($start, null, CarbonInterface::SUNDAY); @@ -44,7 +44,7 @@ function testReturnsTheDaysThatBelongToANormalWeek() $this->assertSame('2014-07-26', $days[6]->toDateString()); } - function testChecksIfADayBelongsToTheCurrentMonth() + public function testChecksIfADayBelongsToTheCurrentMonth() { $start = new Day(2014, 7, 20); $currentMonth = 7; @@ -53,7 +53,7 @@ function testChecksIfADayBelongsToTheCurrentMonth() $this->assertTrue($week->currentMonthDay($day)); } - function testChecksIfADayDoesNotBelongToTheCurrentMonth() + public function testChecksIfADayDoesNotBelongToTheCurrentMonth() { $start = new Day(2014, 7, 20); $currentMonth = 7; @@ -62,7 +62,7 @@ function testChecksIfADayDoesNotBelongToTheCurrentMonth() $this->assertFalse($week->currentMonthDay($day)); } - function testReturnsTheDaysThatBelongToAWeekWithBlankDays() + public function testReturnsTheDaysThatBelongToAWeekWithBlankDays() { $start = new Day(2014, 6, 29); $currentMonth = 7; @@ -82,7 +82,7 @@ function testReturnsTheDaysThatBelongToAWeekWithBlankDays() $this->assertFalse($days[2]->isBlankDay()); } - function testStartsOnCarbonsDefaultStartOfWeek() + public function testStartsOnCarbonsDefaultStartOfWeek() { $start = new Day(2017, 7, 1); $week = new Week($start, null, CarbonInterface::MONDAY); @@ -91,7 +91,7 @@ function testStartsOnCarbonsDefaultStartOfWeek() $this->assertSame(CarbonInterface::MONDAY, $days[0]->dayOfWeek); } - function testStartsOnWhateverDayOfTheWeekCarbonDoes() + public function testStartsOnWhateverDayOfTheWeekCarbonDoes() { $start = new Day(2017, 7, 1); $week = new Week($start, null, CarbonInterface::SUNDAY); @@ -100,7 +100,7 @@ function testStartsOnWhateverDayOfTheWeekCarbonDoes() $this->assertSame(CarbonInterface::SUNDAY, $days[0]->dayOfWeek); } - function testHandlesUsDaylightSavingsTimeStart() + public function testHandlesUsDaylightSavingsTimeStart() { $start = new Day(2017, 3, 12, 'America/New_York'); $currentMonth = 11; @@ -119,7 +119,7 @@ function testHandlesUsDaylightSavingsTimeStart() $this->assertSame('2017-03-18', $days[6]->toDateString()); } - function testHandlesUsDaylightSavingsTimeEnd() + public function testHandlesUsDaylightSavingsTimeEnd() { $start = new Day(2017, 11, 5, 'America/New_York'); $currentMonth = 11; @@ -138,11 +138,11 @@ function testHandlesUsDaylightSavingsTimeEnd() $this->assertSame('2017-11-11', $days[6]->toDateString()); } - function testHandlesUkDaylightSavingsTimeStart() + public function testHandlesUkDaylightSavingsTimeStart() { $start = new Day(2017, 3, 26, 'Europe/London'); $currentMonth = 9; - $week = new Week($start, $currentMonth,CarbonInterface::MONDAY); + $week = new Week($start, $currentMonth, CarbonInterface::MONDAY); $days = $week->getDays(); $this->assertIsIterable($days); @@ -157,7 +157,7 @@ function testHandlesUkDaylightSavingsTimeStart() $this->assertSame('2017-03-26', $days[6]->toDateString()); } - function testHandlesUkDaylightSavingsTimeEnd() + public function testHandlesUkDaylightSavingsTimeEnd() { $start = new Day(2017, 10, 29, 'Europe/London'); $currentMonth = 4; @@ -176,7 +176,7 @@ function testHandlesUkDaylightSavingsTimeEnd() $this->assertSame('2017-10-29', $days[6]->toDateString()); } - function testHandlesNzDaylightSavingsTimeStart() + public function testHandlesNzDaylightSavingsTimeStart() { $start = new Day(2017, 9, 24, 'Pacific/Auckland'); $currentMonth = 9; @@ -195,7 +195,7 @@ function testHandlesNzDaylightSavingsTimeStart() $this->assertSame('2017-09-30', $days[6]->toDateString()); } - function testHandlesNzDaylightSavingsTimeEnd() + public function testHandlesNzDaylightSavingsTimeEnd() { $start = new Day(2018, 4, 2, 'Pacific/Auckland'); $currentMonth = 4;