Skip to content

Commit

Permalink
Added install callback to check the PHP version
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Oct 30, 2013
1 parent 747f3cc commit 8481acd
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -6,9 +6,10 @@ before_script:
- echo "zend.enable_gc=off" >> ~/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/php.ini
- mkdir releases tests/.cache
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then composer install --dev --no-interaction; fi"
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then scripts/installRunkit.sh; fi"
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.3' ]; then phpenv config-rm xdebug.ini; fi"
- php -i
script:
- phpunit -c phpunit-$TRAVIS_PHP_VERSION.xml
after_script:
- sh -c "if [ $TRAVIS_PHP_VERSION = '5.5' ]; then php vendor/bin/coveralls -v; fi"
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then php vendor/bin/coveralls -v; fi"
2 changes: 1 addition & 1 deletion build/addon.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<addon addon_id="s9e" title="s9e Media Pack" url="https://github.com/s9e/XenForoMediaBBCodes" version_id="20131030" version_string="20131030">
<addon addon_id="s9e" title="s9e Media Pack" url="https://github.com/s9e/XenForoMediaBBCodes" version_id="20131030" version_string="20131030" install_callback_class="s9e_MediaBBCodes" install_callback_method="install">
<bb_code_media_sites>
<site media_site_id="bandcamp" site_title="Bandcamp" site_url="http://bandcamp.com/" match_is_regex="1" embed_html_callback_class="s9e_MediaBBCodes" embed_html_callback_method="embed" match_callback_class="s9e_MediaBBCodes" match_callback_method="matchBandcamp">
<match_urls>!bandcamp\.com/album/.!
Expand Down
8 changes: 8 additions & 0 deletions build/upload/library/s9e/MediaBBCodes.php
Expand Up @@ -12,6 +12,14 @@ class s9e_MediaBBCodes
*/
public static $cacheDir;

public static function install()
{
if (version_compare(phpversion(), '5.3', '<'))
{
throw new RuntimeException('Requires PHP 5.3 or later');
}
}

public static function match($url, $regexps, $scrapes)
{
$vars = array();
Expand Down
30 changes: 24 additions & 6 deletions scripts/build.php
Expand Up @@ -30,6 +30,14 @@ class s9e_MediaBBCodes
*/
public static $cacheDir;
public static function install()
{
if (version_compare(phpversion(), '5.3', '<'))
{
throw new RuntimeException('Requires PHP 5.3 or later');
}
}
public static function match($url, $regexps, $scrapes)
{
$vars = array();
Expand Down Expand Up @@ -232,18 +240,28 @@ protected static function getNamedCaptures($string, $regexps)
$dom = new DOMDocument('1.0', 'utf-8');
$addon = $dom->appendChild($dom->createElement('addon'));

// The version is simply the current UTC day, optionally followed by the first argument given to
// this script
$versionId = gmdate('Ymd');

if (isset($_SERVER['argv'][1]))
{
$versionId .= $_SERVER['argv'][1];
}

$addon->setAttribute('addon_id', 's9e');
$addon->setAttribute('title', 's9e Media Pack');
$addon->setAttribute('url', 'https://github.com/s9e/XenForoMediaBBCodes');
$addon->setAttribute('version_id', $versionId);
$addon->setAttribute('version_string', $versionId);
// Set the add-on informations
$attributes = [
'addon_id' => 's9e',
'title' => 's9e Media Pack',
'url' => 'https://github.com/s9e/XenForoMediaBBCodes',
'version_id' => $versionId,
'version_string' => $versionId,
'install_callback_class' => 's9e_MediaBBCodes',
'install_callback_method' => 'install'
];
foreach ($attributes as $attrName => $attrValue)
{
$addon->setAttribute($attrName, $attrValue);
}

$rows = [];
$rows[] = '<tr>';
Expand Down
10 changes: 10 additions & 0 deletions scripts/installRunkit.sh
@@ -0,0 +1,10 @@
#!/bin/bash

wget -O - https://codeload.github.com/php/pecl-php-runkit/tar.gz/master | tar xzf - -C/tmp && \
cd /tmp/pecl-php-runkit-master && \
phpize && \
./configure --enable-runkit-modify --disable-runkit-super --disable-runkit-sandbox && \
make && \
sudo make install && \
echo "extension=runkit.so" >> ~/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/php.ini && \
echo "runkit.internal_override=1" >> ~/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/php.ini
30 changes: 29 additions & 1 deletion tests/Test.php
Expand Up @@ -18,7 +18,35 @@ public function testBuild()

public function testLint()
{
include __DIR__ . '/../build/upload/library/s9e/MediaBBCodes.php';
include_once __DIR__ . '/../build/upload/library/s9e/MediaBBCodes.php';
}

public function testInstall()
{
if (!class_exists('s9e_MediaBBCodes'))
{
include __DIR__ . '/../build/upload/library/s9e/MediaBBCodes.php';
}

s9e_MediaBBCodes::install();
}

/**
* @runInSeparateProcess
* @requires extension runkit
* @expectedException RuntimeException
* @expectedException RuntimeExceptionMessage Requires PHP 5.3 or later
*/
public function testInstallFailure()
{
if (!class_exists('s9e_MediaBBCodes'))
{
include __DIR__ . '/../build/upload/library/s9e/MediaBBCodes.php';
}

runkit_function_redefine('phpversion', '', "return '5.2.5';");

s9e_MediaBBCodes::install();
}

/**
Expand Down
4 changes: 4 additions & 0 deletions www/configure.html

Large diffs are not rendered by default.

0 comments on commit 8481acd

Please sign in to comment.