Skip to content

Commit

Permalink
Merge pull request #164 from spatie/fix/issue-163-merge-hours
Browse files Browse the repository at this point in the history
Fix #163 merge hours
  • Loading branch information
kylekatarnls committed Dec 10, 2020
2 parents 51ebd2e + d1f725b commit b1f6561
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 50 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Coverage

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
coverage:
runs-on: ubuntu-latest

strategy:
matrix:
php: ['7.4']
setup: ['stable']

steps:
- uses: actions/checkout@v2

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

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

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: |
composer require --no-update scrutinizer/ocular;
composer update --prefer-dist --no-progress --no-suggest --prefer-${{ matrix.setup || 'stable' }} ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }};
- name: Run test suite
run: vendor/bin/phpunit --coverage-text --coverage-clover=clover.xml

- name: Coverage
run: bash <(curl -s https://codecov.io/bash)
43 changes: 43 additions & 0 deletions .github/workflows/multi-tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Multi-tester

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
multi-tester:
runs-on: ubuntu-latest

strategy:
matrix:
php: ['7.4']
setup: ['stable']

name: PHP ${{ matrix.php }} - ${{ matrix.setup || 'stable' }}

steps:
- uses: actions/checkout@v2

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

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

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist --no-progress --no-suggest --prefer-${{ matrix.setup || 'stable' }} ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }}

- name: Run test suite
run: vendor/bin/multi-tester
44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Tests

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
setup: ['lowest', 'stable']

name: PHP ${{ matrix.php }} - ${{ matrix.setup || 'stable' }}

steps:
- uses: actions/checkout@v2

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

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

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist --no-progress --no-suggest --prefer-${{ matrix.setup || 'stable' }} ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }}

- name: Run test suite
run: vendor/bin/phpunit --no-coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
coverage
docs
vendor
*.cache
39 changes: 24 additions & 15 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
filter:
excluded_paths: [tests/*]
excluded_paths: [tests/*]

checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true

build:
nodes:
coverage:
tests:
override:
- command: vendor/bin/phpunit --coverage-text --coverage-clover=clover.xml
coverage:
file: clover.xml
format: clover
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/opening-hours.svg?style=flat-square)](https://packagist.org/packages/spatie/opening-hours)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/spatie/opening-hours/master.svg?style=flat-square)](https://travis-ci.org/spatie/opening-hours)
[![Tests](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fspatie%2Fopening-hours%2Fbadge&style=flat-square&label=Build&logo=none)](https://actions-badge.atrox.dev/spatie/opening-hours/goto)
[![Coverage](https://img.shields.io/codecov/c/github/spatie/opening-hours.svg?style=flat-square)](https://codecov.io/github/spatie/opening-hours?branch=master)
[![Quality Score](https://img.shields.io/scrutinizer/g/spatie/opening-hours.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/opening-hours)
[![StyleCI](https://styleci.io/repos/69368104/shield?branch=master)](https://styleci.io/repos/69368104)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/opening-hours.svg?style=flat-square)](https://packagist.org/packages/spatie/opening-hours)
Expand Down
3 changes: 2 additions & 1 deletion src/OpeningHours.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static function mergeOverlappingRanges(array $data, array $excludedKeys =

if ($value instanceof TimeRange) {
$newRanges = [];

foreach ($ranges as $range) {
if ($value->format() === $range->format()) {
continue 2;
Expand Down Expand Up @@ -728,7 +729,7 @@ private static function filterHours(array $data, array $excludedKeys): Generator
continue;
}

if (is_array($value) && isset($value['hours'])) {
if (is_int($key) && is_array($value) && isset($value['hours'])) {
foreach ((array) $value['hours'] as $subKey => $hour) {
yield "$key.$subKey" => $hour;
}
Expand Down
1 change: 1 addition & 0 deletions src/OpeningHoursForDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ protected function guardAgainstTimeRangeOverlaps(array $openingHours)
public function __toString()
{
$values = [];

foreach ($this->openingHours as $openingHour) {
$values[] = (string) $openingHour;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/OpeningHoursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1422,4 +1422,22 @@ public function testMergeOverlappingSupportsHoursAndIgnoreData()
$this->assertNull($monday[0]->getData());
$this->assertSame('09:00-23:00', (string) $monday);
}

public function testHoursRangeAreKept()
{
$data = OpeningHours::mergeOverlappingRanges([
'monday' => [
'hours' => [
'09:00-12:00',
'13:00-18:00',
],
],
]);

$monday = OpeningHours::create($data)->forDay('Monday');

$this->assertNull($monday->getData());
$this->assertNull($monday[0]->getData());
$this->assertSame('09:00-12:00,13:00-18:00', (string) $monday);
}
}

0 comments on commit b1f6561

Please sign in to comment.