Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added functional test

  • Loading branch information...
commit 24d2d5811745fcced938d93b1e7fad233e7bb493 1 parent 81c5ee4
@liuggio authored
View
4 .gitignore
@@ -1,2 +1,4 @@
+bin
vendor
-composer.lock
+composer.lock
+Tests/app/cache
View
15 .travis.yml
@@ -0,0 +1,15 @@
+language: php
+
+php:
+ - "5.3"
+ - "5.4"
+
+before_install:
+ - wget http://cs.sensiolabs.org/get/php-cs-fixer.phar
+
+before_script:
+ - php php-cs-fixer.phar fix -v --dry-run .
+ - composer install --dev
+
+script:
+ - bin/phpunit
View
93 README.md
@@ -1,55 +1,26 @@
Symfony2 Excel bundle
============
+[![Build Status](https://travis-ci.org/liuggio/ExcelBundle.png)](https://travis-ci.org/liuggio/ExcelBundle)
[![Total Downloads](https://poser.pugx.org/liuggio/ExcelBundle/downloads.png)](https://packagist.org/packages/liuggio/ExcelBundle)
[![Latest Stable Version](https://poser.pugx.org/liuggio/ExcelBundle/v/stable.png)](https://packagist.org/packages/liuggio/ExcelBundle)
[![Latest Unstable Version](https://poser.pugx.org/liuggio/ExcelBundle/v/unstable.png)](https://packagist.org/packages/liuggio/ExcelBundle)
This bundle permits you to create an easily modifiable excel object.
-This is just a dependency injection that links
+You should know that csv is faster so I encourage you to use the built-in function for csv: http://php.net/manual-lookup.php?pattern=csv&lang=en&scope=quickref
-3 Objects:
+## Installation
-- The container in this bundle,
+**1** Add to composer.json to the `require` key
-- The StreamWrapper in the n3bStreamresponse
-
-- A Writer.
-
-
-You could create your own writer extending ``n3b\Bundle\Util\HttpFoundation\StreamResponse\StreamWriterInterface`` or you could use the great PHPExcel library. With PHPExcel you can create xls, ods, pdf and more.
-
-You have to know that csv is faster so I encourage you to use the built-in function for csv: http://it.php.net/manual-lookup.php?pattern=csv&lang=en&scope=quickref
-
-## Migration
-
-In order to follow the naming convention https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md all the liuggio namespaces are migrated to Liuggio.
-
-This master is up-to-date to the symfony/symfony master actually on 2.1
-
-
-## INSTALLATION with COMPOSER
-
-1 Add to composer.json to the `require` key
-
-```
+``` yml
"require" : {
- "liuggio/excelbundle": "@dev",
+ "liuggio/excelbundle": "2.0.x-dev",
}
```
-
-
-2 Register the bundle in ``app/AppKernel.php``
-
-``` php
- $bundles = array(
- // ...
- new Liuggio\ExcelBundle\LiuggioExcelBundle(),
- );
-```
-3 Enable the bundle in `app/AppKernel.php`
+**2** Register the bundle in ``app/AppKernel.php``
``` php
$bundles = array(
@@ -58,39 +29,29 @@ This master is up-to-date to the symfony/symfony master actually on 2.1
);
```
+## Services
-
-## AVAILABLE SERVICES
-
-If you want to write
-
-``` php
- // create MS Excel5
- $excelService = $this->get('xls.excel5');
- // create MS Excel 2007
- $this->get('xls.excel2007');
-
-```
-
-If you want to read xls
+The list of the services are listed in `/Resources/config/services.yml`.
``` php
- $excelService = $this->get('xls.excel5')->load($filename);
-
+// create MS Excel5
+$this->get('xls.excel5');
+// create MS Excel 2007
+$this->get('xls.excel2007');
+// read file
+$excelService = $this->get('xls.excel5')->load($filename);
```
-## USAGE
-
-Create a controller in your bundle
+## Example
+Create a controller in your bundle,
+there's a working example at `Tests/app/Controller/FakeController.php`.
``` php
-
namespace YOURNAME\YOURBUNDLE\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-
class DefaultController extends Controller
{
@@ -124,32 +85,24 @@ class DefaultController extends Controller
// If you are using a https connection, you have to set those two headers and use sendHeaders() for compatibility with IE <9
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
- $response->sendHeaders();
+
return $response;
}
}
-
```
-With the right writer (e.g. PHPExcel_Writer_Excel5) you could also write the output to a file:
+With the correct writer (e.g. PHPExcel_Writer_Excel5) you could also write the output to a file:
+
``` php
public function indexAction($name)
{
$excelService = $this->get('xls.excel5');
-
//...load and modify or create php excel object
-
- $excelService->getStreamWriter()->write( $filename );
+ $excelService->getStreamWriter()->write($filename);
}
```
-
-## ADVANCED USE
-
-If you need to, see and modify ``Liuggio\ExcelBundle\Resources\config\services.yml``
-
-
## Contributors
@pivasyk
@@ -164,6 +117,8 @@ If you need to, see and modify ``Liuggio\ExcelBundle\Resources\config\services.y
@mazenovi
+@gnat42
+
@jochenhilgers
@Squazic
View
185 Resources/doc/index.rst
@@ -1,185 +0,0 @@
-Symfony2 Excel bundle
-============
-
-This Bundle permits to create easly Excel object.
-This is just a dependency injection that links
-
-3 Objects:
-
-- The container in this bundle,
-
-- The StreamWrapper in the n3bStreamresponse
-
-- A Writer.
-
-
-You could create your own writer extending ``n3b\Bundle\Util\HttpFoundation\StreamResponse\StreamWriterInterface`` or you could use the Huge Xls library called PHPExcel.
-
-With PHPExcel you can create: xls, ods, pdf and more,
-
-you have to know that csv is pretty faster so I encourage you to use the built-in function for csv http://it.php.net/manual-lookup.php?pattern=csv&lang=en&scope=quickref
-
-## Migration
-
-In order to follow the naming convention https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md all the liuggio namespaces are migrated to Liuggio.
-
-This master is up-to-date to the symfony/symfony master actually on 2.1
-
-
-## INSTALLATION with COMPOSER
-
-1 Add to composer.json to the `require` key
-
-```
-"liuggio/excelbundle": "dev-master",
-```
-
-and add the repositories:
-
-```
- "repositories": {
- "n3bStreamresponse": {
- "type": "package",
- "package": {
- "name": "n3bStreamresponse",
- "version": "master",
- "source": {
- "url": "git://github.com/liuggio/Symfony2-StreamResponse.git",
- "type": "git",
- "reference": "master"
- },
- "autoload": {
- "psr-0": { "n3b\\Bundle\\Util\\HttpFoundation\\StreamResponse": "n3b/src" }
- },
- "target-dir": "n3b/src/n3b/Bundle/Util/HttpFoundation/StreamResponse"
- }
- },
- "phpExcel": {
- "type": "package",
- "package": {
- "name": "phpExcel",
- "version": "master",
- "source": {
- "url": "git://github.com/liuggio/PHPExcel.git",
- "type": "git",
- "reference": "master"
- },
- "autoload": {
- "classmap": ["lib/"]
- }
- }
- }
- },
-
-```
-
-
-2 Register the bundle in ``app/AppKernel.php``
-
-``` php
- $bundles = array(
- // ...
- new Liuggio\ExcelBundle\LiuggioExcelBundle(),
- );
-```
-
-
-
-## AVAILABLE SERVICES
-
-If you want write
-
-``` php
- // create MS Excel5
- $xls_service = $this->get('xls.service_xls5');
- // create pdf
- $this->get('xls.service_pdf');
- // create MS Excel 2007
- $this->get('xls.service_xls2007');
-
-```
-
-
-If you want read xls
-
-``` php
- $exelObj = $this->get('xls.load_xls5')->load($filename);
-
-```
-
-
-
-
-## USAGE
-
-create a controller in your bundle
-
-
-``` php
-
-namespace YOURNAME\YOURBUNDLE\Controller;
-
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-
-
-class DefaultController extends Controller
-{
-
- public function indexAction($name)
- {
- // ask the service for a Excel5
- $xls_service = $this->get('xls.service_xls5');
- // or $this->get('xls.service_pdf');
- // or create your own is easy just modify services.yml
-
-
- // create the object see http://phpexcel.codeplex.com documentation
- $xls_service->excelObj->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2005 XLSX Test Document")
- ->setSubject("Office 2005 XLSX Test Document")
- ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
- ->setKeywords("office 2005 openxml php")
- ->setCategory("Test result file");
- $xls_service->excelObj->setActiveSheetIndex(0)
- ->setCellValue('A1', 'Hello')
- ->setCellValue('B2', 'world!');
- $xls_service->excelObj->getActiveSheet()->setTitle('Simple');
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- $xls_service->excelObj->setActiveSheetIndex(0);
-
- //create the response
- $response = $xls_service->getResponse();
- $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
- $response->headers->set('Content-Disposition', 'attachment;filename=stdream2.xls');
-
- // If you are using a https connection, you have to set those two headers for compatibility with IE <9
- $response->headers->set('Pragma', 'public');
- $response->headers->set('Cache-Control', 'maxage=1');
- return $response;
- }
-}
-
-```
-
-
-
-
-## ADVANCED USE
-
-if you need see and modify ``Liuggio\ExcelBundle\Resources\config\services.yml``
-
-
-## Contributors
-
-@pivasyk
-
-@dirkbl
-
-@DerStoffel
-
-@artturi
-
-@isqad88
-
-@mazenovi
View
8 Service/Excel.php
@@ -68,14 +68,14 @@ public function getWriter($type = null)
public function getStreamWriter()
{
- $stream_writer = new $this->streamWriterClass("php://output");
- $stream_writer->setWriter($this->getWriter(),'save');
+ $streamWriter = new $this->streamWriterClass("php://output");
+ $streamWriter->setWriter($this->getWriter(),'save');
- return $stream_writer;
+ return $streamWriter;
}
/**
- * create the response with the file content
+ * Create the response with the file content.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
View
25 Tests/Controller/FakeControllerTest.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace Liuggio\ExcelBundle\Tests\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+
+class FakeControllerTest extends WebTestCase
+{
+ public function testIndex()
+ {
+ $client = static::createClient();
+
+ $client->request('GET', '/fake');
+
+ ob_start();
+ $client->getResponse()->sendContent();
+ $content = ob_get_contents();
+ ob_end_clean();
+
+ $this->assertEquals(200, $client->getResponse()->getStatusCode(), $client->getResponse()->getContent());
+ $this->assertStringStartsWith('attachment;filename=', $client->getResponse()->headers->get('content-disposition'));
+
+ $this->assertNotNull($content, 'Response should not be null');
+ }
+}
View
25 Tests/app/AppKernel.php
@@ -0,0 +1,25 @@
+<?php
+
+use Symfony\Component\HttpKernel\Kernel;
+use Symfony\Component\Config\Loader\LoaderInterface;
+
+class AppKernel extends Kernel
+{
+ public function registerBundles()
+ {
+ $bundles = array(
+ // Dependencies
+ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
+ new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
+ // My Bundle to test
+ new Liuggio\ExcelBundle\LiuggioExcelBundle(),
+ );
+
+ return $bundles;
+ }
+
+ public function registerContainerConfiguration(LoaderInterface $loader)
+ {
+ $loader->load(__DIR__.'/config.yml');
+ }
+}
View
39 Tests/app/Controller/FakeController.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Liuggio\ExcelBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\HttpFoundation\Response;
+
+class FakeController extends Controller
+{
+ public function indexAction()
+ {
+ $excelService = $this->get('xls.excel5');
+
+ $excelService->excelObj->getProperties()->setCreator("Maarten Balliauw")
+ ->setLastModifiedBy("Maarten Balliauw")
+ ->setTitle("Office 2005 XLSX Test Document")
+ ->setSubject("Office 2005 XLSX Test Document")
+ ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
+ ->setKeywords("office 2005 openxml php")
+ ->setCategory("Test result file");
+ $excelService->excelObj->setActiveSheetIndex(0)
+ ->setCellValue('A1', 'Hello')
+ ->setCellValue('B2', 'world!');
+ $excelService->excelObj->getActiveSheet()->setTitle('Simple');
+ // Set active sheet index to the first sheet, so Excel opens this as the first sheet
+ $excelService->excelObj->setActiveSheetIndex(0);
+
+ //create the response
+ $response = $excelService->getResponse();
+ $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
+ $response->headers->set('Content-Disposition', 'attachment;filename=stdream2.xls');
+
+ // If you are using a https connection, you have to set those two headers and use sendHeaders() for compatibility with IE <9
+ $response->headers->set('Pragma', 'public');
+ $response->headers->set('Cache-Control', 'maxage=1');
+
+ return $response;
+ }
+}
View
0  Tests/app/cache/.gitkeep
No changes.
View
9 Tests/app/config.yml
@@ -0,0 +1,9 @@
+# Tests/Controller/App/config.yml
+framework:
+ secret: secret
+ test: ~
+ router: { resource: "%kernel.root_dir%/routing.yml" }
+ session:
+ storage_id: session.storage.mock_file
+ profiler:
+ collect: false
View
3  Tests/app/routing.yml
@@ -0,0 +1,3 @@
+fake_route:
+ path: /fake
+ defaults: { _controller: LiuggioExcelBundle:Fake:index }
View
10 Tests/bootstrap.php
@@ -0,0 +1,10 @@
+<?php
+
+$file = __DIR__ . '/../vendor/autoload.php';
+if (!file_exists($file)) {
+ throw new RuntimeException('Install dependencies to run test suite.');
+}
+
+$autoload = require_once $file;
+
+require_once __DIR__ . '/app/Controller/FakeController.php';
View
15 composer.json
@@ -21,6 +21,16 @@
"irongit/symfony2-stream-response": ">=1.0",
"phpoffice/phpexcel": "1.7.9"
},
+ "require-dev": {
+ "phpunit/PHPUnit": "3.7.*",
+ "symfony/finder": "~2.0",
+ "symfony/form": "~2.3",
+ "symfony/class-loader": "~2.1",
+ "symfony/validator": "~2.1",
+ "symfony/browser-kit": "~2.1",
+ "sensio/framework-extra-bundle": "~2.3"
+ },
+
"autoload": {
"psr-0": {
"Liuggio\\ExcelBundle": ""
@@ -31,5 +41,8 @@
"dev-master": "2.0.x-dev"
}
},
- "target-dir": "Liuggio/ExcelBundle"
+ "target-dir": "Liuggio/ExcelBundle",
+ "config": {
+ "bin-dir": "bin"
+ }
}
View
12 phpunit.xml.dist
@@ -0,0 +1,12 @@
+<!-- phpunit.xml.dist -->
+<phpunit bootstrap="Tests/bootstrap.php">
+ <testsuites>
+ <testsuite name="ExcelBundle Test Suite">
+ <directory>./Tests</directory>
+ </testsuite>
+ </testsuites>
+
+ <php>
+ <server name="KERNEL_DIR" value="Tests/app" />
+ </php>
+</phpunit>
Please sign in to comment.
Something went wrong with that request. Please try again.