PHP Objects, Patterns, and Practice- P10
Số trang: 50
Loại file: pdf
Dung lượng: 1,020.09 KB
Lượt xem: 13
Lượt tải: 0
Xem trước 5 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
PHP Objects, Patterns, and Practice- P10: This book takes you beyond the PHP basics to the enterprise development practices used by professional programmers. Updated for PHP 5.3 with new sections on closures, namespaces, and continuous integration, this edition will teach you about object features such as abstract classes, reflection, interfaces, and error handling. You’ll also discover object tools to help you learn more about your classes, objects, and methods.
Nội dung trích xuất từ tài liệu:
PHP Objects, Patterns, and Practice- P10 CHAPTER 20 ■ CONTINUOUS INTEGRATIONChapter 18 to illustrate PHPUnit. I’m going to name it userthing, because its a thing, with a User objectin it. First of all, here is a breakdown of my project directory. See Figure 20–1.Figure 20–1. Part of a sample project to illustrate CI As you can see, I’ve tidied up the structure a little, adding some package directories. Within thecode, I’ve supported the package structure with the use of namespaces. Now that I have a project, I should add it to a version control system.CI and Version Control Version control is essential for CI. A CI system needs to acquire the most recent version of a projectwithout human intervention (at least once things have been set up). 429 CHAPTER 20 ■ CONTINUOUS INTEGRATION You may have noticed that I moved the code for userthing into a directory named trunk. That’s because I’m going to import the project into Subversion, and the branches, tags and trunk directories are a useful convention in that system. Here’s the import: $ svn import userthing.orig/ file:///var/local/svn/userthing -mfirst import And heres the checkout. $ svn checkout file:///var/local/svn/userthing/trunk userthing I covered Subversion in more detail in Chapter 17. Now that I have the a local version of my project, I’m going to change my working directory to src/ in order to try out the various tools that my CI implementation will require. $ cd userthing/src Unit Tests Unit tests are the key to continuous integration. It’s no good successfully building a project that contains broken code. I covered unit testing with PHPUnit in Chapter 18. If you’re reading out of order, though, you’ll want to install this invaluable tool before proceeding. $ pear channel-discover pear.phpunit.de $ pear install phpunit Also in Chapter 18 I wrote tests for a version of the userthing code I’ll be working with in this chapter. Here I run them once again, to make sure my reorganization has not broken anything new. $ phpunit test PHPUnit 3.4.11 by Sebastian Bergmann. ..... Time: 0 seconds, Memory: 4.50Mb OK (5 tests, 6 assertions) As you can see, I referenced the filesystem to invoke my tests. I passed the test directory as an argument to PHPUnit, and it automatically sought out my test files. However, one of the CI tools you’ll encounter later, phpUnderControl, prefers that you reference a single class in order to run tests. To support this requirement, I can add a test suite class. Here is UserTests.php: require_once PHPUnit/Framework.php; require_once test/UserStoreTest.php; require_once test/ValidatorTest.php; class UserTests { public static function suite() { $suite = new PHPUnit_Framework_TestSuite(); $suite->addTestSuite(UserStoreTest); $suite->addTestSuite(ValidatorTest);430 CHAPTER 20 ■ CONTINUOUS INTEGRATION return $suite; }}■Note In in this case Ive kept my test classes in the global namespace. Where tests have a close or one to onerelationship to the components they test, however, its often neater to place each test class in the samenamespace as its target, and in a parallel directory structure. That way you can tell at a glance the relationshipbetween a test and its subject both from the tests namespace and the location of its file. The PHPUnit_Framework_TestSuite class allows you to collect individual test cases into a suite. Here’show I can call this from the command line:$ phpunit test/UserTestsPHPUnit 3.4.11 by Sebastian Bergmann......Time: 1 second, Memory: 4.50MbOK (5 tests, 6 assertions)Documentation Transparency is one of the principles of CI. When youre looking at a build in a ContinuousIntegration environment, therefore, it’s important to be able to check that the documentation is up todate, and covers the most recent classes and methods. I examined phpDocumentor in Chapter 16, soI’ve already run an install like this.pear upgrade PhpDocumentor I’d better run the tool just to be sure:$ mkdir docs$ phpdoc --directory userthing --target docs/ That generates some pretty bare documentation. Once that’s published on a CI server, I’m sure tobe shamed into writing some real inline documentation.Code Coverage It’s no good relying on tests if they don’t apply to the code you have written. PHPUnit includes th ...
Nội dung trích xuất từ tài liệu:
PHP Objects, Patterns, and Practice- P10 CHAPTER 20 ■ CONTINUOUS INTEGRATIONChapter 18 to illustrate PHPUnit. I’m going to name it userthing, because its a thing, with a User objectin it. First of all, here is a breakdown of my project directory. See Figure 20–1.Figure 20–1. Part of a sample project to illustrate CI As you can see, I’ve tidied up the structure a little, adding some package directories. Within thecode, I’ve supported the package structure with the use of namespaces. Now that I have a project, I should add it to a version control system.CI and Version Control Version control is essential for CI. A CI system needs to acquire the most recent version of a projectwithout human intervention (at least once things have been set up). 429 CHAPTER 20 ■ CONTINUOUS INTEGRATION You may have noticed that I moved the code for userthing into a directory named trunk. That’s because I’m going to import the project into Subversion, and the branches, tags and trunk directories are a useful convention in that system. Here’s the import: $ svn import userthing.orig/ file:///var/local/svn/userthing -mfirst import And heres the checkout. $ svn checkout file:///var/local/svn/userthing/trunk userthing I covered Subversion in more detail in Chapter 17. Now that I have the a local version of my project, I’m going to change my working directory to src/ in order to try out the various tools that my CI implementation will require. $ cd userthing/src Unit Tests Unit tests are the key to continuous integration. It’s no good successfully building a project that contains broken code. I covered unit testing with PHPUnit in Chapter 18. If you’re reading out of order, though, you’ll want to install this invaluable tool before proceeding. $ pear channel-discover pear.phpunit.de $ pear install phpunit Also in Chapter 18 I wrote tests for a version of the userthing code I’ll be working with in this chapter. Here I run them once again, to make sure my reorganization has not broken anything new. $ phpunit test PHPUnit 3.4.11 by Sebastian Bergmann. ..... Time: 0 seconds, Memory: 4.50Mb OK (5 tests, 6 assertions) As you can see, I referenced the filesystem to invoke my tests. I passed the test directory as an argument to PHPUnit, and it automatically sought out my test files. However, one of the CI tools you’ll encounter later, phpUnderControl, prefers that you reference a single class in order to run tests. To support this requirement, I can add a test suite class. Here is UserTests.php: require_once PHPUnit/Framework.php; require_once test/UserStoreTest.php; require_once test/ValidatorTest.php; class UserTests { public static function suite() { $suite = new PHPUnit_Framework_TestSuite(); $suite->addTestSuite(UserStoreTest); $suite->addTestSuite(ValidatorTest);430 CHAPTER 20 ■ CONTINUOUS INTEGRATION return $suite; }}■Note In in this case Ive kept my test classes in the global namespace. Where tests have a close or one to onerelationship to the components they test, however, its often neater to place each test class in the samenamespace as its target, and in a parallel directory structure. That way you can tell at a glance the relationshipbetween a test and its subject both from the tests namespace and the location of its file. The PHPUnit_Framework_TestSuite class allows you to collect individual test cases into a suite. Here’show I can call this from the command line:$ phpunit test/UserTestsPHPUnit 3.4.11 by Sebastian Bergmann......Time: 1 second, Memory: 4.50MbOK (5 tests, 6 assertions)Documentation Transparency is one of the principles of CI. When youre looking at a build in a ContinuousIntegration environment, therefore, it’s important to be able to check that the documentation is up todate, and covers the most recent classes and methods. I examined phpDocumentor in Chapter 16, soI’ve already run an install like this.pear upgrade PhpDocumentor I’d better run the tool just to be sure:$ mkdir docs$ phpdoc --directory userthing --target docs/ That generates some pretty bare documentation. Once that’s published on a CI server, I’m sure tobe shamed into writing some real inline documentation.Code Coverage It’s no good relying on tests if they don’t apply to the code you have written. PHPUnit includes th ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật lập trình lập trình php lập trình web giáo trình cơ bản lập trình html ngôn ngữ javaGợi ý tài liệu liên quan:
-
Thủ thuật giúp giải phóng dung lượng ổ cứng
4 trang 210 0 0 -
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 202 0 0 -
Bài toán phân luồng giao thông và ứng dụng
11 trang 179 1 0 -
Hướng dẫn lập trình với Android part 4
5 trang 154 0 0 -
[Thảo luận] Học PHP như thế nào khi bạn chưa biết gì về lập trình?
5 trang 131 0 0 -
161 trang 129 1 0
-
142 trang 129 0 0
-
Bài giảng Lập trình web nâng cao: Chương 8 - Trường ĐH Văn Hiến
36 trang 109 1 0 -
MỘT SỐ ĐIỂM CẦN CHÚ Ý KHI THIẾT KẾ WEB
5 trang 108 0 0 -
150 trang 103 0 0