mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-15 06:40:59 +08:00

UrlManager is a complex class with a large bunch of options that needs
to be tested
and we had a few regressions in the past even though there are already a
lot of tests
covering it. Test coverage measured by lines does not help us determine
how good it is tested,
we need test coverage for every major path through the code.
I have refactored the UrlManager tests to reflect the different options
and cases to
have a better overview of which cases are covered and which are not.
UrlManager has two main operation modes:
- "default" url format, which is the simple case. These are covered by
methods in `UrlManagerTest`.
- "pretty" url format. This is the complex case, which involves UrlRules
and url parsing.
I have created two separate classes for this case:
Url creation for "pretty" url format is covered by
`UrlManagerCreateUrlTest`.
Url parsing for "pretty" url format is covered by
`UrlManagerParseUrlTest`.
Each of the test classes have a `getUrlManager` method that creates a
UrlManager instance
with a specific configuration and certain variations in options.
It is also tested that options that are not relevant in a certain
operation mode have no effect on the result.
To make sure to not remove tests that have existed before, here is a map
of where code has been moved.
The following test methods existed in the [old test
class](4187718c14/tests/framework/web/UrlManagerTest.php
):
- `testCreateUrl()` split between UrlManagerTest and
UrlManagerCreateUrlTest variations should all be covered by
`variationsProvider()`.
- `testCreateUrlWithNullParams()` covered by UrlManagerCreateUrlTest by
`testWithNullParams()`
- `testCreateUrlWithEmptyPattern()`
- `testCreateAbsoluteUrl()` covered in UrlManagerCreateUrlTest by new
tests via `variationsProvider()`.
- `testCreateAbsoluteUrlWithSuffix()` covered in UrlManagerCreateUrlTest
by `testAbsolutePatterns`.
- `testParseRequest()` covered by UrlManagerParseUrlTest, UrlNormalizer
related parts moved to UrlNormalizerTest.
- `testParseRESTRequest()` moved to UrlManagerParseUrlTest
- `testHash()` covered in different tests in UrlManagerCreateUrlTest.
- `testMultipleHostsRules($host)` kept as is.
Before:
$ vendor/bin/phpunit tests/framework/web/UrlManagerTest.php
...
OK (12 tests, 89 assertions)
After:
$ vendor/bin/phpunit tests/framework/web/UrlManager*.php
...
OK (72 tests, 648 assertions)
The Definitive Guide to Yii 2.0
This tutorial is released under the Terms of Yii Documentation.
All Rights Reserved.
2014 (c) Yii Software LLC.
Introduction
Getting Started
- Installing Yii
- Running Applications
- Saying Hello
- Working with Forms
- Working with Databases
- Generating Code with Gii
- Looking Ahead
Application Structure
- Overview
- Entry Scripts
- Applications
- Application Components
- Controllers
- Models
- Views
- Modules
- Filters
- Widgets
- Assets
- Extensions
Handling Requests
- Overview
- Bootstrapping
- Routing and URL Creation
- Requests
- Responses
- Sessions and Cookies
- Handling Errors
- Logging
Key Concepts
- Components
- Properties
- Events
- Behaviors
- Configurations
- Aliases
- Class Autoloading
- Service Locator
- Dependency Injection Container
Working with Databases
- Data Access Objects: Connecting to a database, basic queries, transactions, and schema manipulation
- Query Builder: Querying the database using a simple abstraction layer
- Active Record: The Active Record ORM, retrieving and manipulating records, and defining relations
- Migrations: Apply version control to your databases in a team development environment
- Sphinx
- Redis
- MongoDB
- ElasticSearch
Getting Data from Users
- Creating Forms
- Validating Input
- Uploading Files
- Collecting Tabular Input
- Getting Data for Multiple Models
Displaying Data
Security
- Overview
- Authentication
- Authorization
- Working with Passwords
- Cryptography
- Auth Clients
- Best Practices
Caching
RESTful Web Services
- Quick Start
- Resources
- Controllers
- Routing
- Response Formatting
- Authentication
- Rate Limiting
- Versioning
- Error Handling
Development Tools
Testing
Special Topics
- Advanced Project Template
- Building Application from Scratch
- Console Commands
- Core Validators
- Internationalization
- Mailing
- Performance Tuning
- Shared Hosting Environment
- Template Engines
- Working with Third-Party Code
Widgets
- GridView
- ListView
- DetailView
- ActiveForm
- Pjax
- Menu
- LinkPager
- LinkSorter
- Bootstrap Widgets
- jQuery UI Widgets