Skip to content

Commit ab96c75

Browse files
author
Roman Syroeshko
committed
#58 - Part VIII (Autoloader).
1 parent 90a1188 commit ab96c75

File tree

136 files changed

+15881
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+15881
-158
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PhpWord
22

3-
[![Build Status](https://travis-ci.org/PHPOffice/PhpWord.png?branch=master)](https://travis-ci.org/PHPOffice/PhpWord)
3+
[![Build Status](https://travis-ci.org/PhpOffice/PhpWord.png?branch=master)](https://travis-ci.org/PhpOffice/PhpWord)
44
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword) [![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword) [![Latest Unstable Version](https://poser.pugx.org/phpoffice/phpword/v/unstable.png)](https://packagist.org/packages/phpoffice/phpword) [![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
55

66
__OpenXML - Read, Write and Create Word documents in PHP.__

Tests/PhpWord/AutoloaderTest.php

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,36 @@
11
<?php
22
namespace PhpWord\Tests;
33

4-
use PHPWord_Autoloader;
5-
use PHPWord_Autoloader as Autoloader;
4+
use PhpOffice\PhpWord\Autoloader;
65

76
class AutoloaderTest extends \PHPUnit_Framework_TestCase
87
{
98
public function testRegister()
109
{
11-
PHPWord_Autoloader::register();
12-
$this->assertContains(array('PHPWord_Autoloader', 'load'), spl_autoload_functions());
13-
$this->assertContains(array('PHPWord_Autoloader', 'autoload'), spl_autoload_functions());
14-
}
15-
16-
public function testAutoloadLegacy()
17-
{
18-
$this->assertNull(
19-
PHPWord_Autoloader::load('Foo'),
20-
'PHPWord_Autoloader::load() is trying to load classes outside of the PhpWord namespace'
21-
);
22-
$this->assertTrue(
23-
PHPWord_Autoloader::load('PhpWord'),
24-
'PHPWord_Autoloader::load() failed to autoload the PhpWord class'
10+
Autoloader::register();
11+
$this->assertContains(
12+
array('PhpOffice\\PhpWord\\Autoloader', 'autoload'),
13+
\spl_autoload_functions()
2514
);
2615
}
2716

2817
public function testAutoload()
2918
{
30-
$declared = get_declared_classes();
31-
$declaredCount = count($declared);
19+
$declared = \get_declared_classes();
20+
$declaredCount = \count($declared);
3221
Autoloader::autoload('Foo');
3322
$this->assertEquals(
3423
$declaredCount,
35-
count(get_declared_classes()),
36-
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes ' .
37-
'outside of the PhpOffice\\PhpWord namespace'
24+
\count(get_declared_classes()),
25+
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes '
26+
. 'outside of the PhpOffice\\PhpWord namespace'
3827
);
3928
// TODO change this class to the main PhpWord class when it is namespaced
40-
Autoloader::autoload(
41-
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'
42-
);
29+
Autoloader::autoload('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException');
4330
$this->assertTrue(
44-
in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()),
45-
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' .
46-
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
31+
\in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', \get_declared_classes()),
32+
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the '
33+
. 'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
4734
);
4835
}
4936
}

Tests/PhpWord/IOFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace PhpWord\Tests;
33

4-
use PhpOffice\PhpWord;
4+
use PhpOffice\PhpWord\PhpWord;
55
use PhpOffice\PhpWord\IOFactory;
66

77
/**

Tests/PhpWord/MediaTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function testGetFooterMediaElements()
4242
public function testAddSectionMediaElement()
4343
{
4444
$section = new Section(0);
45-
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
46-
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
47-
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
48-
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
49-
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
50-
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
45+
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars_noext_jpg");
46+
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars.jpg");
47+
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mario.gif");
48+
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/firefox.png");
49+
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/duke_nukem.bmp");
50+
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/angela_merkel.tif");
5151

5252
$elements = $section->getElements();
5353
$this->assertEquals(6, count($elements));

Tests/PhpWord/Reader/Word2007Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testCanRead()
2626
{
2727
$dir = join(
2828
DIRECTORY_SEPARATOR,
29-
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
29+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents')
3030
);
3131
$object = new Word2007;
3232
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
@@ -42,7 +42,7 @@ public function testCanReadFailed()
4242
{
4343
$dir = join(
4444
DIRECTORY_SEPARATOR,
45-
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
45+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents')
4646
);
4747
$object = new Word2007;
4848
$file = $dir . DIRECTORY_SEPARATOR . 'foo.docx';
@@ -57,10 +57,10 @@ public function testLoad()
5757
{
5858
$dir = join(
5959
DIRECTORY_SEPARATOR,
60-
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
60+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents')
6161
);
6262
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
6363
$object = IOFactory::load($file);
64-
$this->assertInstanceOf('PhpOffice\\PhpWord', $object);
64+
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object);
6565
}
6666
}

Tests/PhpWord/Section/FooterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testAddImage()
7474
{
7575
$src = \join(
7676
\DIRECTORY_SEPARATOR,
77-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
77+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
7878
);
7979
$oFooter = new Footer(1);
8080
$element = $oFooter->addImage($src);

Tests/PhpWord/Section/HeaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testAddImage()
7070
{
7171
$src = \join(
7272
\DIRECTORY_SEPARATOR,
73-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
73+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
7474
);
7575
$oHeader = new Header(1);
7676
$element = $oHeader->addImage($src);
@@ -113,7 +113,7 @@ public function testAddWatermark()
113113
{
114114
$src = \join(
115115
\DIRECTORY_SEPARATOR,
116-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
116+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
117117
);
118118
$oHeader = new Header(1);
119119
$element = $oHeader->addWatermark($src);

Tests/PhpWord/Section/ImageTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function testConstruct()
1212
{
1313
$src = \join(
1414
\DIRECTORY_SEPARATOR,
15-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
15+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'firefox.png')
1616
);
1717
$oImage = new Image($src);
1818

@@ -27,7 +27,7 @@ public function testConstructWithStyle()
2727
{
2828
$src = \join(
2929
\DIRECTORY_SEPARATOR,
30-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
30+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'firefox.png')
3131
);
3232
$oImage = new Image(
3333
$src,
@@ -43,12 +43,12 @@ public function testConstructWithStyle()
4343
*/
4444
public function testValidImageTypes()
4545
{
46-
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
47-
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
48-
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
49-
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
50-
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
51-
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
46+
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars_noext_jpg");
47+
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars.jpg");
48+
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mario.gif");
49+
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/firefox.png");
50+
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/duke_nukem.bmp");
51+
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/angela_merkel.tif");
5252
}
5353

5454
/**
@@ -57,7 +57,7 @@ public function testValidImageTypes()
5757
*/
5858
public function testImageNotFound()
5959
{
60-
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/thisisnotarealimage");
60+
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/thisisnotarealimage");
6161
}
6262

6363
/**
@@ -66,14 +66,14 @@ public function testImageNotFound()
6666
*/
6767
public function testInvalidImageTypes()
6868
{
69-
new Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx");
69+
new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/alexz-johnson.pcx");
7070
}
7171

7272
public function testStyle()
7373
{
7474
$oImage = new Image(\join(
7575
\DIRECTORY_SEPARATOR,
76-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
76+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
7777
), array('width' => 210, 'height' => 210, 'align' => 'center'));
7878

7979
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
@@ -83,7 +83,7 @@ public function testRelationID()
8383
{
8484
$oImage = new Image(\join(
8585
\DIRECTORY_SEPARATOR,
86-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
86+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
8787
));
8888

8989
$iVal = rand(1, 1000);
@@ -95,7 +95,7 @@ public function testWatermark()
9595
{
9696
$oImage = new Image(\join(
9797
\DIRECTORY_SEPARATOR,
98-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
98+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
9999
));
100100

101101
$oImage->setIsWatermark(true);

Tests/PhpWord/Section/MemoryImageTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function testPNG()
99
{
1010
$src = \join(
1111
\DIRECTORY_SEPARATOR,
12-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
12+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'firefox.png')
1313
);
1414
$oMemoryImage = new MemoryImage($src);
1515

@@ -26,7 +26,7 @@ public function testGIF()
2626
{
2727
$src = \join(
2828
\DIRECTORY_SEPARATOR,
29-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'mario.gif')
29+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'mario.gif')
3030
);
3131
$oMemoryImage = new MemoryImage($src);
3232

@@ -43,7 +43,7 @@ public function testJPG()
4343
{
4444
$src = \join(
4545
\DIRECTORY_SEPARATOR,
46-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
46+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
4747
);
4848
$oMemoryImage = new MemoryImage($src);
4949

@@ -60,7 +60,7 @@ public function testBMP()
6060
{
6161
$oMemoryImage = new MemoryImage(\join(
6262
\DIRECTORY_SEPARATOR,
63-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'duke_nukem.bmp')
63+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'duke_nukem.bmp')
6464
));
6565

6666
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
@@ -74,7 +74,7 @@ public function testStyle()
7474
{
7575
$oMemoryImage = new MemoryImage(\join(
7676
\DIRECTORY_SEPARATOR,
77-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
77+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
7878
), array('width' => 210, 'height' => 210, 'align' => 'center'));
7979

8080
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
@@ -84,7 +84,7 @@ public function testRelationID()
8484
{
8585
$oMemoryImage = new MemoryImage(\join(
8686
\DIRECTORY_SEPARATOR,
87-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
87+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
8888
));
8989

9090
$iVal = rand(1, 1000);

Tests/PhpWord/Section/ObjectTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function testConstructWithSupportedFiles()
99
{
1010
$src = \join(
1111
\DIRECTORY_SEPARATOR,
12-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
12+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
1313
);
1414
$oObject = new Object($src);
1515

@@ -22,7 +22,7 @@ public function testConstructWithNotSupportedFiles()
2222
{
2323
$src = \join(
2424
\DIRECTORY_SEPARATOR,
25-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')
25+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'xsl', 'passthrough.xsl')
2626
);
2727
$oObject = new Object($src);
2828

@@ -35,7 +35,7 @@ public function testConstructWithSupportedFilesAndStyle()
3535
{
3636
$src = \join(
3737
\DIRECTORY_SEPARATOR,
38-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
38+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
3939
);
4040
$oObject = new Object($src, array('width' => '230px'));
4141

@@ -48,7 +48,7 @@ public function testRelationId()
4848
{
4949
$src = \join(
5050
\DIRECTORY_SEPARATOR,
51-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
51+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
5252
);
5353
$oObject = new Object($src);
5454

@@ -61,7 +61,7 @@ public function testImageRelationId()
6161
{
6262
$src = \join(
6363
\DIRECTORY_SEPARATOR,
64-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
64+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
6565
);
6666
$oObject = new Object($src);
6767

@@ -74,7 +74,7 @@ public function testObjectId()
7474
{
7575
$src = \join(
7676
\DIRECTORY_SEPARATOR,
77-
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
77+
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls')
7878
);
7979
$oObject = new Object($src);
8080

0 commit comments

Comments
 (0)