Skip to content

Replace old guide pages with redirects to new pages #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,51 @@ public function buildDocsGuides() {
->sortByName()
->in('guides');

$prevVersionDocs = [
'01-Introduction.md', '02-GettingStarted.md', '03-AcceptanceTests.md', '04-FunctionalTests.md', '05-UnitTests.md', '06-ModulesAndHelpers.md', '06-ReusingTestCode.md', '07-AdvancedUsage.md', '07-BDD.md', '08-Customization.md', '09-Data.md', '10-APITesting.md', '11-Codecoverage.md', '12-ContinuousIntegration.md', '12-ParallelExecution.md','APITesting', 'AcceptanceTests', 'AdvancedUsage', 'BDD', 'Codecoverage', 'ContinuousIntegration', 'Customization', 'Data', 'Debugging', 'FunctionalTests', 'GettingStarted', 'Introduction', 'ModulesAndHelpers', 'ParallelExecution', 'Reporting', 'ReusingTestCode', 'UnitTests',
];
$guidesLinks = [];

foreach ($guides as $file) {
$name = substr($file->getBasename(), 0, -3);
$filename = $file->getBasename();
$name = substr($filename, 0, -3);
$titleName = preg_replace("(\d+-)", '', $name);

$link = "/docs/$titleName";
$editLink = 'https://github.com/Codeception/codeception.github.com/edit/master/guides/' . $file->getBasename();

$editLink = 'https://github.com/Codeception/codeception.github.com/edit/master/guides/' . $filename;
$title = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $titleName);
$title = preg_replace('/([a-z\d])([A-Z])/', '\\1 \\2', $title);

$contents = file_get_contents($file->getPathname());
$pervVersionLink = in_array($file->getBasename(), $prevVersionDocs) ? '<div class="alert alert-success">💡 <b>You are reading docs for latest Codeception 5</b>. <a href="https://github.com/Codeception/codeception.github.com/blob/4.x/docs/' . $file->getBasename() . '">Read for 4.x</a></div>' : '';

foreach ([$file->getBasename(), $titleName . '.md'] as $filename) {
$this->taskWriteToFile('docs/' . $filename)
->line('---')
->line('layout: doc')
->line("title: $title - Codeception Docs")
->line('---')
->line('')
->line($pervVersionLink)
->line('')
->text($contents)
->line('')
->line('<div class="alert alert-warning"><a href="'.$editLink.'"><strong>Improve</strong> this guide</a></div>')
->run();
if (file_exists("docs/4.x/$titleName.md" )) {
$prevVersionLink = '<div class="alert alert-success">💡 <b>You are reading docs for latest Codeception 5</b>. <a href="/docs/4.x/' . $titleName . '">Read for 4.x</a></div>';
} else {
$prevVersionLink = '';
}

$this->taskWriteToFile('docs/' . $titleName . '.md')
->line('---')
->line('layout: doc')
->line("title: $title - Codeception Docs")
->line('---')
->line('')
->line($prevVersionLink)
->line('')
->text($contents)
->line('')
->line('<div class="alert alert-warning"><a href="'.$editLink.'"><strong>Improve</strong> this guide</a></div>')
->run();

$this->taskWriteToFile('docs/' . $filename)
->line('<meta http-equiv="refresh" content="0;url=https://codeception.com/docs/' . $titleName. '">')
->line('---')
->line('layout: doc')
->line("title: $title - Codeception Docs")
->line('---')
->line('')
->line('<div class="alert alert-warning">')
->line(' See <a href="https://codeception.com/docs/' . $titleName . '">' . $title . '</a>')
->line('</div>')
->run();

$guidesLinks[] = "<li><a href=\"$link\">$title</a></li>";
}
file_put_contents('_includes/guides.html', implode("\n", $guidesLinks));
Expand Down
124 changes: 4 additions & 120 deletions docs/01-Introduction.md
Original file line number Diff line number Diff line change
@@ -1,125 +1,9 @@
<meta http-equiv="refresh" content="0;url=https://codeception.com/docs/Introduction">
---
layout: doc
title: Introduction - Codeception Docs
---

<div class="alert alert-success">💡 <b>You are reading docs for latest Codeception 5</b>. <a href="https://github.com/Codeception/codeception.github.com/blob/4.x/docs/01-Introduction.md">Read for 4.x</a></div>

# Introduction

The idea behind testing is not new. You can't sleep well if you are not confident
that your latest commit didn't take down the entire application.
Having your application covered with tests gives you more trust in the stability of your application. That's all.

In most cases tests don't guarantee that the application works 100% as it is supposed to.
You can't predict all possible scenarios and exceptional situations for complex apps,
but with tests you can cover the most important parts of your app and at least be sure they work as predicted.

There are plenty of ways to test your application.
The most popular paradigm is [Unit Testing](https://en.wikipedia.org/wiki/Unit_testing).
For web applications, testing just the controller and/or the model doesn't prove that your application is working.
To test the behavior of your application as a whole, you should write functional or acceptance tests.

Codeception supports all three testing types.
Out of the box you have tools for writing unit, functional, and acceptance tests in a unified framework.

| | Unit Tests | Functional Tests | Acceptance Tests
| --- | --- | --- | --- |
| Scope of the test | Single PHP class | PHP Framework (Routing, Database, etc.) | Page in browser (Chrome, Firefox, or [PhpBrowser](https://codeception.com/docs/03-AcceptanceTests#PhpBrowser)) |
| Testing computer needs access to project's PHP files | Yes | Yes | No |
| Webserver required | No | No | Yes |
| JavaScript | No | No | Yes |
| Additional software required | None | None | Drivers for Firefox/Chrome |
| Test execution speed | Very fast | Fast | Slow |
| Configuration file | `Unit.suite.yml` | `Functional.suite.yml` | `Acceptance.suite.yml` |

One of the main advantages of Codeception is that you don't have to decide on just *one* type of testing. You should have all three!
And chances are, that you will (sooner or later) need all three. That's why Codeception consists of three so-called "suites":
A "Unit suite" for all unit tests, a "functional suite" for all functional tests, and an "Acceptance suite" for all acceptance tests.

Let's review those three test types in reverse order.

### Acceptance Tests

How does your client, manager, tester, or any other non-technical person know your website is working? By opening the browser, accessing the site, clicking on links, filling in the forms, and actually seeing the content on a web page. They have no idea of the programming language, framework, database, web-server,
or why the application did (or did not) behave as expected.

This is what acceptance tests are doing. They cover scenarios from a user's perspective.
With acceptance tests, you can be confident that users, following all the defined scenarios, won't get errors.

> **Any website** can be covered with acceptance tests, even if you use a very exotic CMS or framework.

#### Sample acceptance test

```php
$I->amOnPage('/');
$I->click('Sign Up');
$I->submitForm('#signup', [
'username' => 'MilesDavis',
'email' => 'miles@davis.com'
]);
$I->see('Thank you for Signing Up!');
```

### Functional Tests

What if you could check our application without running it on a server?
That way you could see detailed exceptions on errors, have your tests run faster, and check the database against predictable and expected results. That's what functional tests are for.

For functional tests, you emulate a web request (`$_GET` and `$_POST` variables) which returns the HTML response. Inside a test, you can make assertions about the response, and you can check if the data was successfully stored in the database.

For functional tests, your application needs to be structured in order to run in a test environment. Codeception provides modules for all popular PHP frameworks.

#### Sample functional test

```php
$I->amOnPage('/');
$I->click('Sign Up');
$I->submitForm('#signup', ['username' => 'MilesDavis', 'email' => 'miles@davis.com']);
$I->see('Thank you for Signing Up!');
$I->seeEmailIsSent('miles@davis.com', 'Thank you for your registration');
$I->seeInDatabase('users', ['email' => 'miles@davis.com']);
```

> This looks very similar to acceptance tests. The behavior is the same, however, the test is executed inside PHP without launching a real browser.

### Unit Tests

Testing pieces of code before coupling them together is highly important as well. This way,
you can be sure that some deeply hidden feature still works, even if it was not covered by functional or acceptance tests.
This also shows care in producing stable and testable code.

Codeception is created on top of [PHPUnit](https://www.phpunit.de/). If you have experience writing unit tests with PHPUnit
you can continue doing so. Codeception has no problem executing standard PHPUnit tests,
but, additionally, Codeception provides some well-built tools to make your unit tests simpler and cleaner.

Requirements and code can change rapidly,
and unit tests should be updated every time to fit the requirements.
The better you understand the testing scenario, the faster you can update it for new behavior.

#### Sample integration test

```php
public function testSavingUser()
{
$user = new User();
$user->setName('Miles');
$user->setSurname('Davis');
$user->save();
$this->assertEquals('Miles Davis', $user->getFullName());
$this->tester->seeInDatabase('users', [
'name' => 'Miles',
'surname' => 'Davis'
]);
}
```

## Conclusion

The Codeception framework was developed to actually make testing fun.
It allows writing unit, functional, integration, and acceptance tests in a single, coherent style.

All Codeception tests are written in a descriptive manner.
Just by looking at the test body, you can clearly understand what is being tested and how it is performed.

<div class="alert alert-warning"><a href="https://github.com/Codeception/codeception.github.com/edit/master/guides/01-Introduction.md"><strong>Improve</strong> this guide</a></div>
<div class="alert alert-warning">
See <a href="https://codeception.com/docs/Introduction">Introduction</a>
</div>
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy