Permalink
Browse files

Merge pull request #9 from sanmai/tests

Tested sanmai's changes locally first - the changes work well and I am happy to merge. :-)
  • Loading branch information...
2 parents da5c02d + 9adcd6f commit 8ae5bac5e38cfc0d14d456b6da7331f27a6326c5 @kenguest kenguest committed Oct 6, 2017
Showing with 99 additions and 9 deletions.
  1. +15 −0 .travis.yml
  2. +10 −7 README → README.md
  3. +3 −2 composer.json
  4. +20 −0 phpunit.xml.dist
  5. +51 −0 tests/OLE_Test.php
View
@@ -0,0 +1,15 @@
+sudo: false
+
+language: php
+php:
+ - 5.6
+ - 7.0
+ - 7.1
+
+cache:
+ directories:
+ - $HOME/.composer/cache
+
+install:
+ - composer install --prefer-dist
+
View
@@ -4,16 +4,19 @@ Please report all new issues via the PEAR bug tracker.
If this package is marked as unmaintained and you have fixes, please submit your pull requests and start discussion on the pear-qa mailing list.
-To test, run either
-$ phpunit tests/
- or
-$ pear run-tests -r
+To test, run
+
+ $ composer install
+ $ vendor/bin/phpunit
To build, simply
-$ pear package
+
+ $ pear package
To install from scratch
-$ pear install package.xml
+
+ $ pear install package.xml
To upgrade
-$ pear upgrade -f package.xml
+
+ $ pear upgrade -f package.xml
View
@@ -28,9 +28,10 @@
},
"type": "library",
"require": {
+ "php": ">= 5.6",
"pear/pear_exception": "*"
},
"require-dev": {
- "phpunit/phpunit": "*"
+ "phpunit/phpunit": "<6"
}
-}
+}
View
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit bootstrap="vendor/autoload.php" verbose="true" colors="true">
+ <testsuites>
+ <testsuite>
+ <directory>tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory suffix=".php">OLE/</directory>
+ <file>OLE.php</file>
+ </whitelist>
+ </filter>
+
+ <logging>
+ <log type="coverage-clover" target="build/logs/clover.xml"/>
+ <log type="coverage-text" target="php://stdout"/>
+ </logging>
+</phpunit>
View
@@ -0,0 +1,51 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+// +----------------------------------------------------------------------+
+// | Copyright (c) 2017 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Author: Alexey Kopytko <alexey@kopytko.com> |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+class OLE_Test extends PHPUnit_Framework_TestCase
+{
+ public function testAsc2Ucs()
+ {
+ $ucs = OLE::Asc2Ucs('abc123');
+ $this->assertEquals("a\000b\000c\0001\0002\0003\000", $ucs);
+ }
+
+ public function testLocalDate2OLE()
+ {
+ $data = OLE::LocalDate2OLE(1000000000);
+ $this->assertEquals("\x00\x28\xe7\xb4\x1c\x39\xc1\x01", $data);
+ }
+
+ public function testWrite()
+ {
+ $OLE = new OLE_PPS_File(OLE::Asc2Ucs('Example'));
+ $res = $OLE->init();
+ $this->assertTrue($res);
+ $OLE->append("\x00\x00\x00\x00\x00\x00");
+ $OLE->append("\x01\x01\x01\x01\x01\x01");
+
+ $root = new OLE_PPS_Root(1000000000, 1000000000, array($OLE));
+ ob_start();
+ $res = $root->save('-');
+ $data = ob_get_clean();
+ $this->assertTrue($res);
+
+ // that's 2560 bytes of binary data to compare: using sha1 for simplicity
+ $this->assertEquals(2560, strlen($data));
+ $this->assertEquals('65a2a47ce025b35202dee0b706f541accb438488', sha1($data));
+ }
+}

0 comments on commit 8ae5bac

Please sign in to comment.