Skip to content
This repository has been archived by the owner on Sep 17, 2018. It is now read-only.

Commit

Permalink
Major revamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Basic committed Jul 3, 2017
1 parent 9d7d433 commit fe53ec5
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 416 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vendor/

.idea
.php_cs.cache
.idea
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ php:
- 5.4
- 5.5
- 5.6
- hhvm
- 7.0
- 7.1

before_script:
- composer self-update
Expand All @@ -13,4 +14,4 @@ install:
- composer install --prefer-source --no-interaction

script:
- vendor/bin/phpspec run
- vendor/bin/phpspec run
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Mario Basic
Copyright (c) 2015-2017 Mario Bašić

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
41 changes: 16 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
# Bard

[![Build Status](https://travis-ci.org/laravelista/Bard.svg)](https://travis-ci.org/laravelista/Bard) [![Latest Stable Version](https://poser.pugx.org/laravelista/bard/v/stable.svg)](https://packagist.org/packages/laravelista/bard) [![Total Downloads](https://poser.pugx.org/laravelista/bard/downloads.svg)](https://packagist.org/packages/laravelista/bard) [![Latest Unstable Version](https://poser.pugx.org/laravelista/bard/v/unstable.svg)](https://packagist.org/packages/laravelista/bard) [![License](https://poser.pugx.org/laravelista/bard/license.svg)](https://packagist.org/packages/laravelista/bard) [![Join the chat at https://gitter.im/laravelista/Bard](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/laravelista/Bard?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/laravelista/Bard.svg)](https://travis-ci.org/laravelista/Bard) [![Latest Stable Version](https://poser.pugx.org/laravelista/bard/v/stable.svg)](https://packagist.org/packages/laravelista/bard) [![Total Downloads](https://poser.pugx.org/laravelista/bard/downloads.svg)](https://packagist.org/packages/laravelista/bard) [![Latest Unstable Version](https://poser.pugx.org/laravelista/bard/v/unstable.svg)](https://packagist.org/packages/laravelista/bard) [![License](https://poser.pugx.org/laravelista/bard/license.svg)](https://packagist.org/packages/laravelista/bard) [![Join the chat at https://gitter.im/laravelista/Bard](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/laravelista/Bard?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

![Bard](http://news.cdn.leagueoflegends.com/public/images/pages/2015/breveal/img/Promo_Bard_Reveal_BardFloating.png)

Tired of unstable and bloated PHP sitemap packages?

**Look no more!**

Bard is the simplest PHP Sitemap package, just add some urls and you are ready to go. Did I mention that *it supports multilingual locations aka hreflangs*.

**But wait, there is more.**

If you are using Laravel you'll have access to some *extra awesomeness* with convenient boilerplate that makes creating sitemaps a breeze.

## Features

- Framework Agnostic Sitemap Package
- Laravel Friendly also other Frameworks friendly :)
- Common Sitemap Boilerplate for Laravel and other Frameworks
- Create Sitemaps
- Create Sitemap Index
- Return XML response
- Get XML string
- Input Validation

**Everything is tested like crazy with PhpSpec**


**Look no more!**

Bard is the simplest PHP Sitemap package, just add some URLs and you are ready to go. Did I mention that *it supports multilingual locations aka hreflangs*.

## Syntax

```
$sitemap->addUrl('http://domain.com/contact')
->setPriority(0.8)
->setChangeFrequency('hourly')
->setLastModification(Carbon::now())
->addTranslation('hr', 'http://domain.com/hr/contact');
```

## List of all poems

- [Install me gently](https://github.com/laravelista/Bard/wiki/Installation)
- [Let me show you how to use me](https://github.com/laravelista/Bard/wiki/Usage)
- [Learn the API](https://github.com/laravelista/Bard/wiki/Learn-the-API)
- [Laravel + Bard](https://github.com/laravelista/Bard/wiki/Laravel-and-Bard)
- [Laravel Boilerplate](https://github.com/laravelista/Bard/wiki/Laravel-Boilerplate)


![Bard](http://news.cdn.leagueoflegends.com/public/images/pages/2015/breveal/img/Promo_Bard_Reveal_Mask.png)
15 changes: 7 additions & 8 deletions spec/SitemapIndexSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,38 @@
use Prophecy\Argument;
use Sabre\Xml\Writer;

class SitemapIndexSpec extends ObjectBehavior {

class SitemapIndexSpec extends ObjectBehavior
{
use Matchers;

function let()
public function let()
{
$this->beConstructedWith(new Writer);
}

function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType('Laravelista\Bard\SitemapIndex');
}

function it_adds_sitemap_to_sitemap_index()
public function it_adds_sitemap_to_sitemap_index()
{
$this->addSitemap('http://acme.me/sitemap.xml')->shouldHaveType('Laravelista\Bard\Sitemap');
}

function it_generates_sitemap_index_xml_string()
public function it_generates_sitemap_index_xml_string()
{
$this->addSitemap('http://acme.me/sitemap.xml', Carbon::now());

$this->generate()->shouldBeValidXml();
}

function it_renders_sitemap_index_in_xml_response()
public function it_renders_sitemap_index_in_xml_response()
{
$this->addSitemap('http://acme.me/sitemap.xml', Carbon::now());

//var_dump($this->render()->getWrappedObject()->getContent());

$this->render()->shouldHaveType('Symfony\Component\HttpFoundation\Response');
}

}
12 changes: 6 additions & 6 deletions spec/SitemapSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

class SitemapSpec extends ObjectBehavior
{
function let()
public function let()
{
$this->beConstructedWith('http://acme.me/sitemap.xml');
}

function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType('Laravelista\Bard\Sitemap');
}

function it_sets_location()
public function it_sets_location()
{
$this->setLocation('http://acme.me/sitemap.xml')->shouldReturn(true);
$this->setLocation('http://acme.me/sitemap.xml')->shouldReturn($this);
}

function it_sets_last_modification()
public function it_sets_last_modification()
{
$this->setLastModification(new DateTime("2014-12-22"))->shouldReturn(true);
$this->setLastModification(new DateTime("2014-12-22"))->shouldReturn($this);
}
}
14 changes: 7 additions & 7 deletions spec/UrlSetSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
use Prophecy\Argument;
use Sabre\Xml\Writer;

class UrlSetSpec extends ObjectBehavior {

class UrlSetSpec extends ObjectBehavior
{
use Matchers;

function let()
public function let()
{
$this->beConstructedWith(new Writer);
}

function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType('Laravelista\Bard\UrlSet');
}

function it_adds_url_to_urlset()
public function it_adds_url_to_urlset()
{
$this->addUrl('http://acme.me')->shouldHaveType('Laravelista\Bard\Url');
}

function it_generates_sitemap_xml_string()
public function it_generates_sitemap_xml_string()
{
$this->addUrl('http://acme.me', 1.0, 'monthly', null, [['hreflang' => 'en', 'href' => "http://acme.me/en"]]);

$this->generate()->shouldBeValidXml();
}

function it_renders_sitemap_in_xml_response()
public function it_renders_sitemap_in_xml_response()
{
$this->addUrl('http://acme.me', 1.0, 'monthly', null, [['hreflang' => 'en', 'href' => "http://acme.me/en"]]);

Expand Down
85 changes: 26 additions & 59 deletions spec/UrlSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,63 @@
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class UrlSpec extends ObjectBehavior {

function let()
class UrlSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith('http://acme.me');
}

function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType('Laravelista\Bard\Url');
}

function it_sets_priority()
public function it_sets_priority()
{
// Test all from 0.0 to 1.0
for ($i = 0.0; $i <= 1; $i += 0.1)
{
$this->setPriority($i)->shouldReturn(true);
for ($i = 0.0; $i <= 1; $i += 0.1) {
$this->setPriority($i)->shouldReturn($this);
}
}

function it_cannot_set_priority()
public function it_cannot_set_priority()
{
$this->shouldThrow('Laravelista\Bard\Exceptions\ValidationException')->duringSetPriority(22);
$this->shouldThrow('Laravelista\Bard\Exceptions\ValidationException')->duringSetPriority(1.1);
$this->shouldThrow('Laravelista\Bard\Exceptions\ValidationException')->duringSetPriority(- 1);
$this->shouldThrow('Exception')->duringSetPriority(22);
$this->shouldThrow('Exception')->duringSetPriority(1.1);
$this->shouldThrow('Exception')->duringSetPriority(- 1);
}

function it_sets_location()
public function it_sets_location()
{
$this->setLocation('http://acme.me')->shouldReturn(true);
$this->setLocation('http://acme.me')->shouldReturn($this);
}

function it_sets_change_frequency()
public function it_sets_change_frequency()
{
// Test all valid values for change frequency field
foreach ($this->getValidChangeFrequencyValues() as $changeFrequency)
{
$this->setChangeFrequency($changeFrequency)->shouldReturn(true);
}
}

function it_cannot_set_change_frequency()
{
$this->shouldThrow('Laravelista\Bard\Exceptions\ValidationException')->duringSetChangeFrequency('from time to time');
}

function it_sets_last_modification()
{
$this->setLastModification(new DateTime("2014-12-22"))->shouldReturn(true);
}

function it_sets_translations()
{
$translations = [
[
'hreflang' => 'en',
'href' => "http://acme.me/en"
],
[
'hreflang' => 'de',
'href' => "http://acme.me/de"
]
$validChangeFrequencyValues = [
"always", "hourly", "daily", "weekly",
"monthly", "yearly", "never"
];

$this->setTranslations($translations)->shouldReturn(true);
foreach ($validChangeFrequencyValues as $changeFrequency) {
$this->setChangeFrequency($changeFrequency)->shouldReturn($this);
}
}

function it_cannot_set_translations()
public function it_cannot_set_change_frequency()
{
$this->shouldThrow('Laravelista\Bard\Exceptions\ValidationException')->duringSetTranslations(["bla"]);
$this->shouldThrow('Laravelista\Bard\Exceptions\ValidationException')->duringSetTranslations([['bla', 'bla']]);
$this->shouldThrow('Exception')->duringSetChangeFrequency('from time to time');
}

function it_adds_a_translation()
public function it_sets_last_modification()
{
$this->addTranslation('de', "http://acme.me/de")->shouldReturn(true);

$translation = [
'hreflang' => 'de',
'href' => "http://acme.me/de"
];

$this->addTranslation($translation)->shouldReturn(true);
$this->setLastModification(new DateTime("2014-12-22"))->shouldReturn($this);
}

function it_cannot_add_a_translation()
public function it_adds_a_translation()
{
$this->shouldThrow('Exception')->duringAddTranslation('de', "http://acme.me/de", "be");

$this->shouldThrow('Laravelista\Bard\Exceptions\ValidationException')->duringAddTranslation(["bla"]);
$this->addTranslation('de', "http://acme.me/de")->shouldReturn($this);
}
}
7 changes: 0 additions & 7 deletions src/Exceptions/ValidationException.php

This file was deleted.

18 changes: 10 additions & 8 deletions src/Helpers/Matchers.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<?php namespace Laravelista\Bard\Helpers;
<?php

trait Matchers {
namespace Laravelista\Bard\Helpers;

trait Matchers
{
/**
* getMatchers() should return an array with keys describing the expectations and values the closures
* containing the logic of the expectations. The first parameter in the closure is the output
* of the executed method.
*
* @return array
*/
function getMatchers()
public function getMatchers()
{
return [
// Checks if the given $result is valid xml
'beValidXml' => function ($result)
{
if ( ! simplexml_load_string($result)) return false;
'beValidXml' => function ($result) {
if (! simplexml_load_string($result)) {
return false;
}

return true;
}
];
}

}
}
8 changes: 5 additions & 3 deletions src/Interfaces/Generatable.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php namespace Laravelista\Bard\Interfaces;
<?php

interface Generatable {
namespace Laravelista\Bard\Interfaces;

interface Generatable
{
/**
* @return string
*/
public function generate();
}
}
Loading

0 comments on commit fe53ec5

Please sign in to comment.