From dc9c3c3af887962a7b58e82d9ffabf3930305396 Mon Sep 17 00:00:00 2001 From: hirohitoqwe Date: Fri, 9 Aug 2024 18:38:04 +0300 Subject: [PATCH] remove useless setters update tests update xml files for updated tests --- .gitignore | 2 ++ README.md | 17 +++------------- src/Tags/Url.php | 20 ------------------- tests/ImageTest.php | 2 -- tests/NewsTest.php | 2 -- tests/SitemapGeneratorTest.php | 2 +- tests/SitemapTest.php | 14 ------------- tests/UrlTest.php | 18 ----------------- tests/VideoTest.php | 2 -- ...atorTest__it_can_generate_a_sitemap__1.xml | 12 ----------- ...ibutes_while_generating_the_sitemap__1.xml | 13 +----------- ...orTest__it_can_use_a_custom_profile__1.xml | 2 -- ..._if_hasCrawled()_does_not_return_it__1.xml | 10 ---------- ..._url_of_shouldCrawl()_returns_false__1.xml | 8 -------- ...annot_be_added_twice_to_the_sitemap__1.xml | 2 -- ...annot_be_added_twice_to_the_sitemap__1.xml | 2 -- ..._object_can_be_added_to_the_sitemap__1.xml | 2 -- ..._string_can_be_added_to_the_sitemap__1.xml | 2 -- ...ternate_can_be_added_to_the_sitemap__1.xml | 2 -- ..._an_url_with_all_its_set_properties__1.xml | 2 -- ...t_can_render_an_url_with_priority_0__1.xml | 2 -- ...tiple_urls_can_be_added_in_one_call__1.xml | 4 ---- ...le_urls_can_be_added_to_the_sitemap__1.xml | 4 ---- ...st__sitemapable_object_can_be_added__1.xml | 8 -------- ...t__sitemapable_objects_can_be_added__1.xml | 6 ------ 25 files changed, 7 insertions(+), 153 deletions(-) diff --git a/.gitignore b/.gitignore index 46eecc2..9f04947 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ vendor .php_cs.cache .phpunit.result.cache .php-cs-fixer.cache +/.idea +/.phpunit.cache diff --git a/README.md b/README.md index b83191e..2371339 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,7 @@ Sitemap::create() ->add(Url::create('/home') ->setLastModificationDate(Carbon::yesterday()) - ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) - ->setPriority(0.1)) - + ->add(...) ->writeToFile($path); @@ -40,9 +38,7 @@ SitemapGenerator::create('https://example.com') ->getSitemap() ->add(Url::create('/extra-page') ->setLastModificationDate(Carbon::yesterday()) - ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) - ->setPriority(0.1)) - + ->add(...) ->writeToFile($path); @@ -85,8 +81,6 @@ class Post extends Model implements Sitemapable // Return with fine-grained control: return Url::create(route('blog.post.show', $this)) ->setLastModificationDate(Carbon::create($this->updated_at)) - ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) - ->setPriority(0.1); } } ``` @@ -209,14 +203,10 @@ The generated sitemap will look similar to this: https://example.com 2016-01-01T00:00:00+00:00 - daily - 0.8 https://example.com/page 2016-01-01T00:00:00+00:00 - daily - 0.8 ... @@ -272,8 +262,7 @@ use Spatie\Sitemap\Tags\Url; SitemapGenerator::create('https://example.com') ->hasCrawled(function (Url $url) { if ($url->segment(1) === 'contact') { - $url->setPriority(0.9) - ->setLastModificationDate(Carbon::create('2016', '1', '1')); + $url->setLastModificationDate(Carbon::create('2016', '1', '1')) } return $url; diff --git a/src/Tags/Url.php b/src/Tags/Url.php index 21b65e5..f742552 100644 --- a/src/Tags/Url.php +++ b/src/Tags/Url.php @@ -19,10 +19,6 @@ class Url extends Tag public Carbon $lastModificationDate; - public string $changeFrequency; - - public float $priority = 0.8; - /** @var \Spatie\Sitemap\Tags\Alternate[] */ public array $alternates = []; @@ -43,8 +39,6 @@ public static function create(string $url): static public function __construct(string $url) { $this->url = $url; - - $this->changeFrequency = static::CHANGE_FREQUENCY_DAILY; } public function setUrl(string $url = ''): static @@ -61,20 +55,6 @@ public function setLastModificationDate(DateTimeInterface $lastModificationDate) return $this; } - public function setChangeFrequency(string $changeFrequency): static - { - $this->changeFrequency = $changeFrequency; - - return $this; - } - - public function setPriority(float $priority): static - { - $this->priority = max(0, min($priority, 1)); - - return $this; - } - public function addAlternate(string $url, string $locale = ''): static { $this->alternates[] = new Alternate($url, $locale); diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 8003b60..f9ed7be 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -8,8 +8,6 @@ https://localhost - daily - 0.8 https://localhost/favicon.ico Favicon diff --git a/tests/NewsTest.php b/tests/NewsTest.php index f7808c0..afe71bc 100644 --- a/tests/NewsTest.php +++ b/tests/NewsTest.php @@ -11,8 +11,6 @@ https://example.com - daily - 0.8 News name diff --git a/tests/SitemapGeneratorTest.php b/tests/SitemapGeneratorTest.php index 2386514..76d619d 100644 --- a/tests/SitemapGeneratorTest.php +++ b/tests/SitemapGeneratorTest.php @@ -51,7 +51,7 @@ SitemapGenerator::create('http://localhost:4020') ->hasCrawled(function (Url $url) { if ($url->segment(1) === 'page3') { - $url->setPriority(0.6); + $url->setLastModificationDate($this->now->subDay()); } return $url; diff --git a/tests/SitemapTest.php b/tests/SitemapTest.php index 3584e22..c04d34c 100644 --- a/tests/SitemapTest.php +++ b/tests/SitemapTest.php @@ -91,20 +91,6 @@ ->add( Url::create('/home') ->setLastModificationDate($this->now->subDay()) - ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) - ->setPriority(0.1) - ); - - assertMatchesXmlSnapshot($this->sitemap->render()); -}); - -it('can render an url with priority 0', function () { - $this->sitemap - ->add( - Url::create('/home') - ->setLastModificationDate($this->now->subDay()) - ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) - ->setPriority(0.0) ); assertMatchesXmlSnapshot($this->sitemap->render()); diff --git a/tests/UrlTest.php b/tests/UrlTest.php index 8b422e1..0dc94be 100755 --- a/tests/UrlTest.php +++ b/tests/UrlTest.php @@ -35,24 +35,6 @@ ->toEqual($carbon->toAtomString()); }); -test('priority can be set') - ->tap(fn () => $this->url->setPriority(0.1)) - ->expect(fn () => $this->url->priority) - ->toEqual(0.1); - -test('priority is clamped') - ->tap(fn () => $this->url->setPriority(-0.1)) - ->expect(fn () => $this->url->priority) - ->toEqual(0) - ->tap(fn () => $this->url->setPriority(1.1)) - ->expect(fn () => $this->url->priority) - ->toEqual(1); - -test('change frequency can be set') - ->tap(fn () => $this->url->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)) - ->expect(fn () => $this->url->changeFrequency) - ->toEqual(Url::CHANGE_FREQUENCY_YEARLY); - test('alternate can be added', function () { $url = 'defaultUrl'; $locale = 'en'; diff --git a/tests/VideoTest.php b/tests/VideoTest.php index 470cfa6..b1d9aed 100644 --- a/tests/VideoTest.php +++ b/tests/VideoTest.php @@ -9,8 +9,6 @@ https://example.com - daily - 0.8 https://example.com/image.jpg My Test Title diff --git a/tests/__snapshots__/SitemapGeneratorTest__it_can_generate_a_sitemap__1.xml b/tests/__snapshots__/SitemapGeneratorTest__it_can_generate_a_sitemap__1.xml index ae60f24..69c847f 100644 --- a/tests/__snapshots__/SitemapGeneratorTest__it_can_generate_a_sitemap__1.xml +++ b/tests/__snapshots__/SitemapGeneratorTest__it_can_generate_a_sitemap__1.xml @@ -2,32 +2,20 @@ http://localhost:4020/ - daily - 0.8 http://localhost:4020/page1 - daily - 0.8 http://localhost:4020/page2 - daily - 0.8 http://localhost:4020/page3 - daily - 0.8 http://localhost:4020/page4 - daily - 0.8 http://localhost:4020/page5 - daily - 0.8 diff --git a/tests/__snapshots__/SitemapGeneratorTest__it_can_modify_the_attributes_while_generating_the_sitemap__1.xml b/tests/__snapshots__/SitemapGeneratorTest__it_can_modify_the_attributes_while_generating_the_sitemap__1.xml index 08bec9b..cb7b4f7 100644 --- a/tests/__snapshots__/SitemapGeneratorTest__it_can_modify_the_attributes_while_generating_the_sitemap__1.xml +++ b/tests/__snapshots__/SitemapGeneratorTest__it_can_modify_the_attributes_while_generating_the_sitemap__1.xml @@ -2,32 +2,21 @@ http://localhost:4020/ - daily - 0.8 http://localhost:4020/page1 - daily - 0.8 http://localhost:4020/page2 - daily - 0.8 http://localhost:4020/page3 - daily - 0.6 + 2015-12-31T00:00:00+00:00 http://localhost:4020/page4 - daily - 0.8 http://localhost:4020/page5 - daily - 0.8 diff --git a/tests/__snapshots__/SitemapGeneratorTest__it_can_use_a_custom_profile__1.xml b/tests/__snapshots__/SitemapGeneratorTest__it_can_use_a_custom_profile__1.xml index 08eb8cc..a62e959 100644 --- a/tests/__snapshots__/SitemapGeneratorTest__it_can_use_a_custom_profile__1.xml +++ b/tests/__snapshots__/SitemapGeneratorTest__it_can_use_a_custom_profile__1.xml @@ -2,7 +2,5 @@ http://localhost:4020/ - daily - 0.8 diff --git a/tests/__snapshots__/SitemapGeneratorTest__it_will_not_add_the_url_to_the_sitemap_if_hasCrawled()_does_not_return_it__1.xml b/tests/__snapshots__/SitemapGeneratorTest__it_will_not_add_the_url_to_the_sitemap_if_hasCrawled()_does_not_return_it__1.xml index a7559a0..3c3a10d 100644 --- a/tests/__snapshots__/SitemapGeneratorTest__it_will_not_add_the_url_to_the_sitemap_if_hasCrawled()_does_not_return_it__1.xml +++ b/tests/__snapshots__/SitemapGeneratorTest__it_will_not_add_the_url_to_the_sitemap_if_hasCrawled()_does_not_return_it__1.xml @@ -2,27 +2,17 @@ http://localhost:4020/ - daily - 0.8 http://localhost:4020/page1 - daily - 0.8 http://localhost:4020/page2 - daily - 0.8 http://localhost:4020/page4 - daily - 0.8 http://localhost:4020/page5 - daily - 0.8 diff --git a/tests/__snapshots__/SitemapGeneratorTest__it_will_not_crawl_an_url_of_shouldCrawl()_returns_false__1.xml b/tests/__snapshots__/SitemapGeneratorTest__it_will_not_crawl_an_url_of_shouldCrawl()_returns_false__1.xml index 0234a03..0f3a861 100644 --- a/tests/__snapshots__/SitemapGeneratorTest__it_will_not_crawl_an_url_of_shouldCrawl()_returns_false__1.xml +++ b/tests/__snapshots__/SitemapGeneratorTest__it_will_not_crawl_an_url_of_shouldCrawl()_returns_false__1.xml @@ -2,22 +2,14 @@ http://localhost:4020/ - daily - 0.8 http://localhost:4020/page1 - daily - 0.8 http://localhost:4020/page2 - daily - 0.8 http://localhost:4020/page4 - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__a_url_object_cannot_be_added_twice_to_the_sitemap__1.xml b/tests/__snapshots__/SitemapTest__a_url_object_cannot_be_added_twice_to_the_sitemap__1.xml index d132ccb..647cf5c 100644 --- a/tests/__snapshots__/SitemapTest__a_url_object_cannot_be_added_twice_to_the_sitemap__1.xml +++ b/tests/__snapshots__/SitemapTest__a_url_object_cannot_be_added_twice_to_the_sitemap__1.xml @@ -2,7 +2,5 @@ http://localhost/home - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__an_url_cannot_be_added_twice_to_the_sitemap__1.xml b/tests/__snapshots__/SitemapTest__an_url_cannot_be_added_twice_to_the_sitemap__1.xml index d132ccb..647cf5c 100644 --- a/tests/__snapshots__/SitemapTest__an_url_cannot_be_added_twice_to_the_sitemap__1.xml +++ b/tests/__snapshots__/SitemapTest__an_url_cannot_be_added_twice_to_the_sitemap__1.xml @@ -2,7 +2,5 @@ http://localhost/home - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__an_url_object_can_be_added_to_the_sitemap__1.xml b/tests/__snapshots__/SitemapTest__an_url_object_can_be_added_to_the_sitemap__1.xml index d132ccb..647cf5c 100644 --- a/tests/__snapshots__/SitemapTest__an_url_object_can_be_added_to_the_sitemap__1.xml +++ b/tests/__snapshots__/SitemapTest__an_url_object_can_be_added_to_the_sitemap__1.xml @@ -2,7 +2,5 @@ http://localhost/home - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__an_url_string_can_be_added_to_the_sitemap__1.xml b/tests/__snapshots__/SitemapTest__an_url_string_can_be_added_to_the_sitemap__1.xml index d132ccb..647cf5c 100644 --- a/tests/__snapshots__/SitemapTest__an_url_string_can_be_added_to_the_sitemap__1.xml +++ b/tests/__snapshots__/SitemapTest__an_url_string_can_be_added_to_the_sitemap__1.xml @@ -2,7 +2,5 @@ http://localhost/home - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__an_url_with_an_alternate_can_be_added_to_the_sitemap__1.xml b/tests/__snapshots__/SitemapTest__an_url_with_an_alternate_can_be_added_to_the_sitemap__1.xml index 2da2bbc..146824d 100644 --- a/tests/__snapshots__/SitemapTest__an_url_with_an_alternate_can_be_added_to_the_sitemap__1.xml +++ b/tests/__snapshots__/SitemapTest__an_url_with_an_alternate_can_be_added_to_the_sitemap__1.xml @@ -4,7 +4,5 @@ http://localhost/home - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__it_can_render_an_url_with_all_its_set_properties__1.xml b/tests/__snapshots__/SitemapTest__it_can_render_an_url_with_all_its_set_properties__1.xml index ada9e27..d5113cd 100644 --- a/tests/__snapshots__/SitemapTest__it_can_render_an_url_with_all_its_set_properties__1.xml +++ b/tests/__snapshots__/SitemapTest__it_can_render_an_url_with_all_its_set_properties__1.xml @@ -3,7 +3,5 @@ http://localhost/home 2015-12-31T00:00:00+00:00 - yearly - 0.1 diff --git a/tests/__snapshots__/SitemapTest__it_can_render_an_url_with_priority_0__1.xml b/tests/__snapshots__/SitemapTest__it_can_render_an_url_with_priority_0__1.xml index 80329d8..d5113cd 100644 --- a/tests/__snapshots__/SitemapTest__it_can_render_an_url_with_priority_0__1.xml +++ b/tests/__snapshots__/SitemapTest__it_can_render_an_url_with_priority_0__1.xml @@ -3,7 +3,5 @@ http://localhost/home 2015-12-31T00:00:00+00:00 - yearly - 0.0 diff --git a/tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_in_one_call__1.xml b/tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_in_one_call__1.xml index 79cc640..709ec11 100644 --- a/tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_in_one_call__1.xml +++ b/tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_in_one_call__1.xml @@ -2,12 +2,8 @@ http://localhost - daily - 0.8 http://localhost/home - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_to_the_sitemap__1.xml b/tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_to_the_sitemap__1.xml index 6accc0d..2f7c34d 100644 --- a/tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_to_the_sitemap__1.xml +++ b/tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_to_the_sitemap__1.xml @@ -2,12 +2,8 @@ http://localhost/home - daily - 0.8 http://localhost/contact - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__sitemapable_object_can_be_added__1.xml b/tests/__snapshots__/SitemapTest__sitemapable_object_can_be_added__1.xml index f404232..21894a4 100644 --- a/tests/__snapshots__/SitemapTest__sitemapable_object_can_be_added__1.xml +++ b/tests/__snapshots__/SitemapTest__sitemapable_object_can_be_added__1.xml @@ -2,22 +2,14 @@ http://localhost - daily - 0.8 http://localhost/home - daily - 0.8 http://localhost/blog/post-1 - daily - 0.8 http://localhost/blog/post-2 - daily - 0.8 diff --git a/tests/__snapshots__/SitemapTest__sitemapable_objects_can_be_added__1.xml b/tests/__snapshots__/SitemapTest__sitemapable_objects_can_be_added__1.xml index 219da6c..94f9707 100644 --- a/tests/__snapshots__/SitemapTest__sitemapable_objects_can_be_added__1.xml +++ b/tests/__snapshots__/SitemapTest__sitemapable_objects_can_be_added__1.xml @@ -2,17 +2,11 @@ http://localhost/blog/post-1 - daily - 0.8 http://localhost/blog/post-2 - daily - 0.8 http://localhost/blog/post-3 - daily - 0.8