Skip to content

Commit

Permalink
Document test and cs check better.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Aug 3, 2017
1 parent 02e80a3 commit 5190137
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
/vendor/
/build/
/tmp/
composer.lock
composer.phar
phpunit.phar
Expand Down
28 changes: 25 additions & 3 deletions README.md
Expand Up @@ -31,17 +31,21 @@ There are always some providers changing their URLs/API or some new ones which a

## Installation

Add the dependency to your `composer.json`:
Run
```bash
php composer.phar require dereuromark/media-embed
```
This will get the latest tagged version for you.

Or manually add the dependency to your `composer.json`:
```json
{
"require": {
"dereuromark/media-embed": "0.*"
}
}
```

run:
and run:

```bash
php composer.phar install
Expand Down Expand Up @@ -229,5 +233,23 @@ You can see live examples when you get this repo running locally and browse to `
## Contribute / TODOs
See [wiki](https://github.com/dereuromark/MediaEmbed/wiki).

Run tests with
```
composer test-setup
composer test
```

Run coverage
```
composer test-coverage
```
and browse to the genrated `tmp/index.php` via browser.

Run CS check/fix with
```
composer cs-check
composer cs-fix
```

## Credits
Inspired by [autoembed](http://autoembed.com/) which already included most of the supported services and laid the foundation of this OOP approach here.
19 changes: 14 additions & 5 deletions composer.json
Expand Up @@ -10,15 +10,24 @@
"homepage": "http://www.dereuromark.de"
}
],
"autoload": {
"psr-0": {
"": "src/"
}
},
"require": {
"php": ">=5.4"
},
"require-dev":{
"fig-r/psr2r-sniffer": "dev-master"
},
"autoload": {
"psr-0": {
"": "src/"
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
"test": "phpunit",
"test-coverage": "phpunit --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --coverage-clover tmp/coverage/coverage.xml",
"test-setup": "[ ! -f phpunit.phar ] && wget https://phar.phpunit.de/phpunit.phar || true",
"cs-check": "phpcs -v -p --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --ignore=/vendor/,/tmp/,/tests/test_files/ --extensions=php ./",
"cs-fix": "phpcbf -v --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --ignore=/vendor/,/tmp/,/tests/test_files/ --extensions=php ./"
}
}
1 change: 0 additions & 1 deletion examples/index.php
Expand Up @@ -100,7 +100,6 @@

echo '<div><h3>Embed code:</h3><textarea>' . htmlspecialchars($embed) . '</textarea></div>';


echo '</td><td>';
$id = $Object->id();
$slug = $Object->slug();
Expand Down
23 changes: 13 additions & 10 deletions src/MediaEmbed/MediaEmbed.php
Expand Up @@ -97,19 +97,22 @@ public function parseId($id, $host, $config = []) {
*/
public function parseUrl($url, $config = []) {
foreach ($this->_hosts as $stub) {
if ($match = $this->_matchUrl($url, (array)$stub['url-match'])) {
$this->_match = $match;
$match = $this->_matchUrl($url, (array)$stub['url-match']);
if (!$match) {
continue;
}

if (!empty($stub['fetch-match'])) {
if (!$this->_parseLink($url, $stub['fetch-match'])) {
return null;
}
}
$this->_match = $match;

$stub['match'] = $this->_match;
$Object = $this->object($stub, $config + $this->config);
return $Object;
if (!empty($stub['fetch-match'])) {
if (!$this->_parseLink($url, $stub['fetch-match'])) {
return null;
}
}

$stub['match'] = $this->_match;
$Object = $this->object($stub, $config + $this->config);
return $Object;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/MediaEmbed/Object/MediaObject.php
Expand Up @@ -119,6 +119,8 @@ public function stub($property = null, $value = null) {

/**
* {@inheritdoc}
*
* @return string
*/
public function id() {
$res = $this->_match;
Expand All @@ -140,13 +142,17 @@ public function id() {

/**
* {@inheritdoc}
*
* @return string
*/
public function slug() {
return $this->_stub['slug'];
}

/**
* {@inheritdoc}
*
* @return string
*/
public function name() {
$res = $this->_match;
Expand Down

0 comments on commit 5190137

Please sign in to comment.