mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-23 18:54:24 +00:00
Expand and refine development guidelines
Added detailed setup instructions, including Docker and asset management steps. Updated guidelines on testing structure, code quality tools, debugging, and deployment processes. Enhanced clarity and streamlined processes for developers. Updated `TicketTest` with additional tests for `externalRef`.
This commit is contained in:
parent
fc61dfdf3a
commit
7633e587bb
@ -50,53 +50,257 @@ The ticket bundle is developed using a kind of "Command" pattern. The controller
|
||||
|
||||
## Development Guidelines
|
||||
|
||||
### Building the Project
|
||||
### Building and Configuration Instructions
|
||||
|
||||
All the command should be run through the `symfony` command, which will configure the required variables.
|
||||
|
||||
For assets, we must ensure that we use node at version `^20.0.0`. This is done using `nvm use 20`.
|
||||
|
||||
#### Initial Setup
|
||||
|
||||
1. **Clone the Repository**:
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
cd chill-bundles
|
||||
```
|
||||
|
||||
2. **Install PHP Dependencies**:
|
||||
```bash
|
||||
composer install
|
||||
```
|
||||
|
||||
3. **Install JavaScript Dependencies**:
|
||||
```bash
|
||||
nvm use 20
|
||||
yarn install
|
||||
```
|
||||
|
||||
4. **Configure Environment Variables**:
|
||||
|
||||
- Create a `.env.local` file with minimal configuration
|
||||
```bash
|
||||
echo "APP_ENV=dev" >> .env.local
|
||||
```
|
||||
|
||||
5. Start the associated services (database, and so on):
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
5. **Set Up the Database**:
|
||||
```bash
|
||||
# Create the database
|
||||
symfony console doctrine:database:create
|
||||
|
||||
# Run migrations
|
||||
symfony console doctrine:migrations:migrate
|
||||
|
||||
# Load fixtures (optional)
|
||||
symfony console doctrine:fixtures:load
|
||||
```
|
||||
|
||||
6. **Build Assets**:
|
||||
```bash
|
||||
nvm use 20
|
||||
yarn run encore dev
|
||||
```
|
||||
|
||||
7. **Start the Development Server**:
|
||||
```bash
|
||||
symfony server:start -d
|
||||
```
|
||||
|
||||
#### Docker Setup
|
||||
|
||||
The project includes Docker configuration for easier development:
|
||||
|
||||
1. **Start Docker Services**:
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
2. **Access the Application**:
|
||||
- The application will be available at `http://localhost:8000`
|
||||
- PostgreSQL will be available at `localhost:5432`
|
||||
- Redis will be available at `localhost:6379`
|
||||
|
||||
#### Building Assets
|
||||
|
||||
Before submitting any changes, you should build the project to ensure that all assets are properly compiled:
|
||||
|
||||
```bash
|
||||
# For production
|
||||
yarn run encore production
|
||||
```
|
||||
|
||||
For development with hot-reloading:
|
||||
|
||||
```bash
|
||||
# For development with hot-reloading
|
||||
yarn run encore dev --watch
|
||||
|
||||
# for development
|
||||
yarn run encore dev
|
||||
```
|
||||
|
||||
### Testing
|
||||
#### Configuration Files
|
||||
|
||||
The project uses PHPUnit for testing. Each bundle has its own test suite, and there's also a global test suite at the root level. When making changes, you should run the relevant tests to ensure that your changes don't break existing functionality.
|
||||
Key configuration files:
|
||||
|
||||
The tests are run globally, but each bundle is within a test suite.
|
||||
- `config/packages/*.yaml`: Symfony bundle configurations
|
||||
- `webpack.config.js`: Webpack Encore configuration
|
||||
- `composer.json`: PHP dependencies and scripts
|
||||
- `package.json`: JavaScript dependencies and scripts
|
||||
- `.env`: Default environment variables. Must usually not be updated: use `.env.local` instead.
|
||||
|
||||
### Testing Information
|
||||
|
||||
The project uses PHPUnit for testing. Each bundle has its own test suite, and there's also a global test suite at the root level.
|
||||
|
||||
For creating mock, we prefer using prophecy (library phpspec/prophecy).
|
||||
|
||||
#### Running Tests
|
||||
|
||||
```bash
|
||||
# to run test for a bundle "Name":
|
||||
# Run all tests
|
||||
vendor/bin/phpunit
|
||||
|
||||
# Run tests for a specific bundle
|
||||
vendor/bin/phpunit --testsuite NameBundle
|
||||
|
||||
# Run a specific test file
|
||||
vendor/bin/phpunit path/to/TestFile.php
|
||||
|
||||
# Run a specific test method
|
||||
vendor/bin/phpunit --filter methodName path/to/TestFile.php
|
||||
```
|
||||
|
||||
### Code Style
|
||||
#### Test Structure
|
||||
|
||||
The project uses ESLint for JavaScript/TypeScript code quality. You can run the linter with:
|
||||
Tests are organized by bundle and follow the same structure as the bundle itself:
|
||||
|
||||
- Unit tests: Test individual components in isolation
|
||||
- Integration tests: Test components working together
|
||||
- Functional tests: Test the application from the user's perspective
|
||||
|
||||
#### Writing Tests
|
||||
|
||||
Tests should be placed in the appropriate bundle's test directory. For example, tests for the TicketBundle should be placed in `src/Bundle/ChillTicketBundle/tests/`.
|
||||
|
||||
Here's an example of a simple entity test:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace Chill\TicketBundle\Tests\Entity;
|
||||
|
||||
use Chill\TicketBundle\Entity\Ticket;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TicketTest extends TestCase
|
||||
{
|
||||
public function testGetAndSetExternalRef(): void
|
||||
{
|
||||
$ticket = new Ticket();
|
||||
$externalRef = 'REF-123';
|
||||
|
||||
// Set the external reference
|
||||
$ticket->setExternalRef($externalRef);
|
||||
|
||||
// Verify that getExternalRef returns the correct value
|
||||
self::assertSame($externalRef, $ticket->getExternalRef());
|
||||
|
||||
// Change the external reference
|
||||
$newExternalRef = 'REF-456';
|
||||
$ticket->setExternalRef($newExternalRef);
|
||||
|
||||
// Verify that getExternalRef returns the updated value
|
||||
self::assertSame($newExternalRef, $ticket->getExternalRef());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Test Database
|
||||
|
||||
For tests that require a database, the project uses an in-memory SQLite database by default. You can configure a different database for testing in the `.env.test` file.
|
||||
|
||||
### Code Quality Tools
|
||||
|
||||
The project uses several tools to maintain code quality:
|
||||
|
||||
#### PHP Code Style
|
||||
|
||||
The project uses PHP-CS-Fixer for code style. You can run it with:
|
||||
|
||||
```bash
|
||||
# Using the composer script
|
||||
composer php-cs-fixer
|
||||
|
||||
# Or directly
|
||||
php-cs-fixer fix --config=./.php-cs-fixer.dist.php
|
||||
```
|
||||
|
||||
#### Static Analysis
|
||||
|
||||
The project uses PHPStan for static analysis. You can run it with:
|
||||
|
||||
```bash
|
||||
# Using the composer script
|
||||
composer phpstan
|
||||
|
||||
# Or directly
|
||||
vendor/bin/phpstan analyse
|
||||
```
|
||||
|
||||
#### Automated Refactoring
|
||||
|
||||
The project uses Rector for automated refactoring. You can run it with:
|
||||
|
||||
```bash
|
||||
# Using the composer script
|
||||
composer rector
|
||||
|
||||
# Or directly
|
||||
vendor/bin/rector
|
||||
```
|
||||
|
||||
#### JavaScript/TypeScript Linting
|
||||
|
||||
The project uses ESLint for JavaScript/TypeScript code quality. You can run it with:
|
||||
|
||||
```bash
|
||||
yarn run eslint
|
||||
```
|
||||
|
||||
For PHP, we use three tools:
|
||||
|
||||
- php-cs-fixer, that we can run using globally installed php-cs-fixer command;
|
||||
- phpstan, that we can run using `vendor/bin/phpstan`. We use level phpstan level 5.
|
||||
- rector, that we can run using `vendor/bin/rector`.
|
||||
|
||||
## Deployment
|
||||
|
||||
The project can be deployed in a production environment following Symfony's deployment guidelines. The documentation provides detailed instructions for setting up a production environment.
|
||||
|
||||
### Production Deployment Checklist
|
||||
|
||||
1. Set environment variables for production
|
||||
2. Optimize Composer autoloader: `composer install --no-dev --optimize-autoloader`
|
||||
3. Compile assets for production: `yarn run encore production`
|
||||
4. Clear and warm up the cache: `php bin/console cache:clear --env=prod`
|
||||
5. Run database migrations: `php bin/console doctrine:migrations:migrate --env=prod`
|
||||
|
||||
## Documentation
|
||||
|
||||
Comprehensive documentation is available in the `/docs/` directory, including installation instructions, configuration guides, and operational procedures.
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **Create a Feature Branch**: Always create a new branch for your feature or bugfix
|
||||
2. **Write Tests**: Write tests for your changes before implementing them
|
||||
3. **Implement Changes**: Implement your changes following the project's coding standards
|
||||
4. **Run Tests**: Make sure all tests pass
|
||||
5. **Run Code Quality Tools**: Make sure your code passes all code quality checks
|
||||
6. **Submit a Pull Request**: Submit a pull request for review
|
||||
|
||||
## Debugging
|
||||
|
||||
The project includes several tools for debugging:
|
||||
|
||||
- **Symfony Profiler**: Available in development mode at `/_profiler`
|
||||
- **Xdebug**: Configure your IDE to use Xdebug for step-by-step debugging
|
||||
- **Symfony Debug Toolbar**: Available at the bottom of the page in development mode
|
||||
|
||||
## Conclusion
|
||||
|
||||
When working with this project, Junie should:
|
||||
@ -105,3 +309,4 @@ When working with this project, Junie should:
|
||||
2. Build the project before submitting changes to ensure assets are properly compiled
|
||||
3. Run relevant tests to ensure changes don't break existing functionality
|
||||
4. Follow the established code style and patterns
|
||||
5. Use the provided tools for debugging and code quality
|
||||
|
@ -89,4 +89,23 @@ class TicketTest extends KernelTestCase
|
||||
self::assertCount(1, $ticket->getCurrentAddressee());
|
||||
self::assertSame($group, $ticket->getCurrentAddressee()[0]);
|
||||
}
|
||||
|
||||
public function testGetAndSetExternalRef(): void
|
||||
{
|
||||
$ticket = new Ticket();
|
||||
$externalRef = 'REF-123';
|
||||
|
||||
// Set the external reference
|
||||
$ticket->setExternalRef($externalRef);
|
||||
|
||||
// Verify that getExternalRef returns the correct value
|
||||
self::assertSame($externalRef, $ticket->getExternalRef());
|
||||
|
||||
// Change the external reference
|
||||
$newExternalRef = 'REF-456';
|
||||
$ticket->setExternalRef($newExternalRef);
|
||||
|
||||
// Verify that getExternalRef returns the updated value
|
||||
self::assertSame($newExternalRef, $ticket->getExternalRef());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user