diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ca5f45b..2dd8873 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: true matrix: - php: [7.1, 7.2, 7.3, 7.4] + php: [7.4] dependency-version: [prefer-lowest, prefer-stable] name: P${{ matrix.php }} - ${{ matrix.dependency-version }} diff --git a/composer.json b/composer.json index 5a7e3a0..e4d5cdd 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,11 @@ "astrotomic/php-conditional-proxy": "^0.2.0" }, "require-dev": { - "pestphp/pest": "^0.1.5", - "spatie/pest-plugin-snapshots": "^0.1.0" + "pestphp/pest": "^0.3.0", + "spatie/pest-plugin-snapshots": "^0.3.0" + }, + "suggest": { + "php": "^7.4" }, "config": { "sort-packages": true diff --git a/src/StructuredProperties/Audio.php b/src/StructuredProperties/Audio.php index 6b64ea4..2e16bbe 100644 --- a/src/StructuredProperties/Audio.php +++ b/src/StructuredProperties/Audio.php @@ -2,22 +2,10 @@ namespace Astrotomic\OpenGraph\StructuredProperties; -use Astrotomic\OpenGraph\BaseObject; - -class Audio extends BaseObject +class Audio extends StructuredProperty { protected const PREFIX = 'og:audio'; - public function __construct(string $url) - { - $this->setProperty(self::PREFIX, 'url', $url); - } - - public static function make(string $url) - { - return new static($url); - } - public function secureUrl(string $url) { $this->setProperty(self::PREFIX, 'secure_url', $url); diff --git a/src/StructuredProperties/Image.php b/src/StructuredProperties/Image.php index e2ab1e1..b2f86d9 100644 --- a/src/StructuredProperties/Image.php +++ b/src/StructuredProperties/Image.php @@ -2,22 +2,10 @@ namespace Astrotomic\OpenGraph\StructuredProperties; -use Astrotomic\OpenGraph\BaseObject; - -class Image extends BaseObject +class Image extends StructuredProperty { protected const PREFIX = 'og:image'; - public function __construct(string $url) - { - $this->setProperty(self::PREFIX, 'url', $url); - } - - public static function make(string $url) - { - return new static($url); - } - public function secureUrl(string $url) { $this->setProperty(self::PREFIX, 'secure_url', $url); diff --git a/src/StructuredProperties/StructuredProperty.php b/src/StructuredProperties/StructuredProperty.php new file mode 100644 index 0000000..6f16ab3 --- /dev/null +++ b/src/StructuredProperties/StructuredProperty.php @@ -0,0 +1,23 @@ +setProperty(static::PREFIX, 'url', $url); + } else { + $prefix = explode(':', static::PREFIX, 2); + $this->setProperty($prefix[0], $prefix[1], $url); + } + } + + public static function make(string $url, bool $withUrlSuffix = true) + { + return new static($url, $withUrlSuffix); + } +} diff --git a/src/StructuredProperties/Video.php b/src/StructuredProperties/Video.php index 9a5e7df..55405d0 100644 --- a/src/StructuredProperties/Video.php +++ b/src/StructuredProperties/Video.php @@ -2,22 +2,10 @@ namespace Astrotomic\OpenGraph\StructuredProperties; -use Astrotomic\OpenGraph\BaseObject; - -class Video extends BaseObject +class Video extends StructuredProperty { protected const PREFIX = 'og:video'; - public function __construct(string $url) - { - $this->setProperty(self::PREFIX, 'url', $url); - } - - public static function make(string $url) - { - return new static($url); - } - public function secureUrl(string $url) { $this->setProperty(self::PREFIX, 'secure_url', $url); diff --git a/tests/GlobalTypesTest.php b/tests/GlobalTypesTest.php index 80a2590..7346ae7 100644 --- a/tests/GlobalTypesTest.php +++ b/tests/GlobalTypesTest.php @@ -1,10 +1,12 @@ group('global', 'website'); +it('can generate website tags with structured image', function () { + $og = Website::make('Title | Example') + ->url('http://www.example.com') + ->description('Description') + ->locale('en_US') + ->alternateLocale('en_GB') + ->siteName('Example') + ->image(Image::make('http://www.example.com/image1.jpg')->mimeType('image/jpeg')); + + assertMatchesHtmlSnapshot((string) $og); +})->group('global', 'website'); + +it('can generate website tags with structured image without url suffix', function () { + $og = Website::make('Title | Example') + ->url('http://www.example.com') + ->description('Description') + ->locale('en_US') + ->alternateLocale('en_GB') + ->siteName('Example') + ->image(Image::make('http://www.example.com/image1.jpg', false)->mimeType('image/jpeg')); + + assertMatchesHtmlSnapshot((string) $og); +})->group('global', 'website'); + it('can generate website tags with conditional callbacks', function () { $og = Website::make('Title | Example') ->url('http://www.example.com') diff --git a/tests/MusicTypesTest.php b/tests/MusicTypesTest.php index 16b90c7..4119631 100644 --- a/tests/MusicTypesTest.php +++ b/tests/MusicTypesTest.php @@ -4,6 +4,7 @@ use Astrotomic\OpenGraph\Types\Music\Playlist; use Astrotomic\OpenGraph\Types\Music\RadioStation; use Astrotomic\OpenGraph\Types\Music\Song; +use function Spatie\Snapshots\{assertMatchesHtmlSnapshot}; it('can generate song tags', function () { $og = Song::make('Title | Example') diff --git a/tests/TwitterTypesTest.php b/tests/TwitterTypesTest.php index 1ae00d6..3521d8c 100644 --- a/tests/TwitterTypesTest.php +++ b/tests/TwitterTypesTest.php @@ -3,6 +3,7 @@ use Astrotomic\OpenGraph\Types\Twitter\Player; use Astrotomic\OpenGraph\Types\Twitter\Summary; use Astrotomic\OpenGraph\Types\Twitter\SummaryLargeImage; +use function Spatie\Snapshots\{assertMatchesHtmlSnapshot}; it('can generate summary tags', function () { $og = Summary::make('Title | Example') diff --git a/tests/VideoTypesTest.php b/tests/VideoTypesTest.php index 29c66f2..abdda3e 100644 --- a/tests/VideoTypesTest.php +++ b/tests/VideoTypesTest.php @@ -6,6 +6,7 @@ use Astrotomic\OpenGraph\Types\Video\Movie; use Astrotomic\OpenGraph\Types\Video\Other; use Astrotomic\OpenGraph\Types\Video\TvShow; +use function Spatie\Snapshots\{assertMatchesHtmlSnapshot}; it('can generate movie tags', function () { $og = Movie::make('Title | Example') diff --git a/tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_structured_image__1.html b/tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_structured_image__1.html new file mode 100644 index 0000000..eed52c9 --- /dev/null +++ b/tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_structured_image__1.html @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_structured_image_without_url_suffix__1.html b/tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_structured_image_without_url_suffix__1.html new file mode 100644 index 0000000..51087eb --- /dev/null +++ b/tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_structured_image_without_url_suffix__1.html @@ -0,0 +1,12 @@ + + + + + + + + + + + +