Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
722 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Badges [![Latest Stable Version](https://poser.pugx.org/midnite81/badges/version)](https://packagist.org/packages/midnite81/badges) [![Total Downloads](https://poser.pugx.org/midnite81/badges/downloads)](https://packagist.org/packages/midnite81/badges) [![Latest Unstable Version](https://poser.pugx.org/midnite81/badges/v/unstable)](https://packagist.org/packages/midnite81/badges) [![License](https://poser.pugx.org/midnite81/badges/license.svg)](https://packagist.org/packages/midnite81/badges) [![Build](https://travis-ci.org/midnite81/badges.svg?branch=master)](https://travis-ci.org/midnite81/badges) [![Coverage Status](https://coveralls.io/repos/github/midnite81/badges/badge.svg?branch=master)](https://coveralls.io/github/midnite81/badges?branch=master) | ||
_A PHP package to render out package badges_ | ||
|
||
# Installation | ||
|
||
This package requires PHP 5.6+ | ||
|
||
To install through composer include the package in your `composer.json`. | ||
|
||
"midnite81/badges": "^1.0.0" | ||
|
||
Run `composer install` or `composer update` to download the dependencies or you can | ||
run `composer require midnite81/badges`. | ||
|
||
## Badges Supported | ||
|
||
| Type | Example | | ||
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
|Latest Stable |[![Latest Stable Version](https://poser.pugx.org/midnite81/badges/version)](https://packagist.org/packages/midnite81/badges) | | ||
|Total Downloads |[![Total Downloads](https://poser.pugx.org/midnite81/badges/downloads)](https://packagist.org/packages/midnite81/badges) | | ||
|Latest Unstable |[![Latest Unstable Version](https://poser.pugx.org/midnite81/badges/v/unstable)](https://packagist.org/packages/midnite81/badges) | | ||
|Licence |[![License](https://poser.pugx.org/midnite81/badges/license.svg)](https://packagist.org/packages/midnite81/badges) | | ||
|Build |[![Build](https://travis-ci.org/midnite81/badges.svg?branch=master)](https://travis-ci.org/midnite81/badges) | | ||
|Coverage |[![Coverage Status](https://coveralls.io/repos/github/midnite81/badges/badge.svg?branch=master)](https://coveralls.io/github/midnite81/badges?branch=master)| | ||
|
||
Over time support for other badges will be added. You can create your own templates which extend | ||
`Midnite81\Badges\Type\BadgeType` and can be passed through the `$badges->get(MyClass::class)` method. More | ||
documentation on adding your own templates will be added later. | ||
|
||
## Example Usage | ||
|
||
Firstly, you need to create an instance of badges. | ||
|
||
```php | ||
use Midnite81\Badges\Badges; | ||
$badges = new Badges($attributes); | ||
// or | ||
$badges = Badges::create($attributes); | ||
``` | ||
|
||
You'll notice that a variable of $attributes is passed on construction. The attributes are what the package will use | ||
to translate the template. By default we're only going to pass the following attributes as they are needed for the | ||
supported badges. Obviously update the above attributes to suit your own needs. | ||
|
||
```php | ||
$attributes = ['$PACKAGE_NAME$' => 'midnite81/badges']; | ||
``` | ||
|
||
Once the class is instantiated, you then need to select the type of badge you want. | ||
|
||
```php | ||
$myBadge = $this->latestStableVersion(); | ||
``` | ||
|
||
This will return you a `Writer` object, which you can call `->toHtml()` or `->toMarkdown` on for the final rendering | ||
of the badge. The default `_toString` method will return the html version. | ||
|
||
So all in all; | ||
|
||
``` | ||
use Midnite81\Badges\Badges; | ||
$badges = Badges::create(['$PACKAGE_NAME$' => 'midnite81/badges']); | ||
echo $badges->latestStableVersion()->toMarkdown(); | ||
``` | ||
will output | ||
|
||
[![Latest Stable Version](https://poser.pugx.org/midnite81/badges/version)](https://packagist.org/packages/midnite81/badges) | ||
|
||
`[![Latest Stable Version](https://poser.pugx.org/midnite81/badges/version)](https://packagist.org/packages/midnite81/badges)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<?php | ||
|
||
namespace Midnite81\Badges\Tests; | ||
|
||
use Midnite81\Badges\Badges; | ||
use Midnite81\Badges\Type\Licence; | ||
use Midnite81\Badges\Writer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BadgesTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_instantiates() | ||
{ | ||
$badge = $this->getInstance(); | ||
|
||
$this->assertInstanceOf(Badges::class, $badge); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_factory_instantiates() | ||
{ | ||
$badge = $this->getFactoryInstance(); | ||
|
||
$this->assertInstanceOf(Badges::class, $badge); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_latest_stable_version() | ||
{ | ||
$badge = $this->getInstance()->latestStableVersion(); | ||
|
||
$this->assertInstanceOf(Writer::class, $badge); | ||
$this->assertInternalType('string', $badge->toHtml()); | ||
$this->assertInternalType('string', $badge->toMarkdown()); | ||
$this->assertContains('<a href', $badge->toHtml()); | ||
$this->assertContains('[![', $badge->toMarkdown()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_total_download() | ||
{ | ||
$badge = $this->getInstance()->totalDownloads(); | ||
|
||
$this->assertInstanceOf(Writer::class, $badge); | ||
$this->assertInternalType('string', $badge->toHtml()); | ||
$this->assertInternalType('string', $badge->toMarkdown()); | ||
$this->assertContains('<a href', $badge->toHtml()); | ||
$this->assertContains('[![', $badge->toMarkdown()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_latest_unstable_version() | ||
{ | ||
$badge = $this->getInstance()->latestUnstableVersion(); | ||
|
||
$this->assertInstanceOf(Writer::class, $badge); | ||
$this->assertInternalType('string', $badge->toHtml()); | ||
$this->assertInternalType('string', $badge->toMarkdown()); | ||
$this->assertContains('<a href', $badge->toHtml()); | ||
$this->assertContains('[![', $badge->toMarkdown()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_licence() | ||
{ | ||
$badge = $this->getInstance()->licence(); | ||
|
||
$this->assertInstanceOf(Writer::class, $badge); | ||
$this->assertInternalType('string', $badge->toHtml()); | ||
$this->assertInternalType('string', $badge->toMarkdown()); | ||
$this->assertContains('<a href', $badge->toHtml()); | ||
$this->assertContains('[![', $badge->toMarkdown()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_build() | ||
{ | ||
$badge = $this->getInstance()->build(); | ||
|
||
$this->assertInstanceOf(Writer::class, $badge); | ||
$this->assertInternalType('string', $badge->toHtml()); | ||
$this->assertInternalType('string', $badge->toMarkdown()); | ||
$this->assertContains('<a href', $badge->toHtml()); | ||
$this->assertContains('[![', $badge->toMarkdown()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_coverage_status() | ||
{ | ||
$badge = $this->getInstance()->coverageStatus(); | ||
|
||
$this->assertInstanceOf(Writer::class, $badge); | ||
$this->assertInternalType('string', $badge->toHtml()); | ||
$this->assertInternalType('string', $badge->toMarkdown()); | ||
$this->assertContains('<a href', $badge->toHtml()); | ||
$this->assertContains('[![', $badge->toMarkdown()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_writer_from_get_method() | ||
{ | ||
$badge = $this->getInstance()->get(Licence::class); | ||
|
||
$this->assertInstanceOf(Writer::class, $badge); | ||
$this->assertInternalType('string', $badge->toHtml()); | ||
$this->assertInternalType('string', $badge->toMarkdown()); | ||
$this->assertContains('<a href', $badge->toHtml()); | ||
$this->assertContains('[![', $badge->toMarkdown()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @expectedException \Midnite81\Badges\Exceptions\ClassShouldBeInstanceOfBadgeType | ||
*/ | ||
public function it_throws_exception_if_class_is_not_type_of_badge_type() | ||
{ | ||
$badge = $this->getInstance()->get(TestClass::class); | ||
} | ||
|
||
|
||
/** | ||
* Get Instance | ||
* | ||
* @param array $attributes | ||
* @return Badges | ||
*/ | ||
protected function getInstance($attributes = []) | ||
{ | ||
$attributes = (! empty($attributes)) ? $attributes : ['$PACKAGE_NAME$' => 'test/test']; | ||
return new Badges($attributes); | ||
} | ||
|
||
/** | ||
* Get Factory Instance | ||
* | ||
* @param array $attributes | ||
* @return static | ||
*/ | ||
public function getFactoryInstance($attributes = []) | ||
{ | ||
$attributes = (! empty($attributes)) ? $attributes : ['$PACKAGE_NAME$' => 'test/test']; | ||
return Badges::create($attributes); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Midnite81\Badges\Tests; | ||
|
||
class TestClass | ||
{ | ||
// empty class to us in tests | ||
|
||
public function __construct($attributes) | ||
{ | ||
|
||
} | ||
|
||
public static function create($attributes) | ||
{ | ||
return new static($attributes); | ||
} | ||
} |
Oops, something went wrong.