From 43eb39e237d89c9dd62875cef23a3d982e0be1e4 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Mon, 7 Jul 2025 14:54:40 -0300 Subject: [PATCH 1/5] PM-25300 Add Sourcery usage on iOS architecture. --- custom-words.txt | 1 + docs/architecture/mobile-clients/ios/index.md | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/custom-words.txt b/custom-words.txt index 01336186f..d79939f37 100644 --- a/custom-words.txt +++ b/custom-words.txt @@ -71,6 +71,7 @@ SDLC Serilog signtool signup +Sourcery sqlcmd struct structs diff --git a/docs/architecture/mobile-clients/ios/index.md b/docs/architecture/mobile-clients/ios/index.md index 46c3b31cd..a7c2071be 100644 --- a/docs/architecture/mobile-clients/ios/index.md +++ b/docs/architecture/mobile-clients/ios/index.md @@ -444,3 +444,27 @@ This makes it convenient to switch between these files or open them side-by-side mode, dark mode, and with a large dynamic type size. ⚠️ These tests are done using an **iPhone 15 Pro (17.0.1)** simulator, otherwise tests may fail because of subtle differences between iOS versions. + +### Mocks generation + +We use [Sourcery](https://github.com/krzysztofzablocki/Sourcery) for automatic mock generation. + +In order to automatically generate a mock from a protocol, just add a comment with +`// sourcery: AutoMockable` to such protocol, perform a build and the mock will be automatically +generated and added to the `AutoMockable.generated.swift` file. + +For example: + +```swift +protocol FooProtocol { // sourcery: AutoMockable + func bar() -> Bool +} +``` + +:::info Manual generation + +There are some cases where the automatically generated mock does not cover the mock scenario we want +or it cannot handle some closure types, specially in function's parameters. In such cases prefer +create the mock manually and remove the protocol's comment as `AutoMockable`. + +::: From a29213592cca9a0f991f560412f7e9b8b41a6b5e Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Fri, 25 Jul 2025 16:56:01 -0300 Subject: [PATCH 2/5] PM-23500 Added section for Sourcery custom annotations. --- docs/architecture/mobile-clients/ios/index.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/architecture/mobile-clients/ios/index.md b/docs/architecture/mobile-clients/ios/index.md index a7c2071be..6feca23ea 100644 --- a/docs/architecture/mobile-clients/ios/index.md +++ b/docs/architecture/mobile-clients/ios/index.md @@ -468,3 +468,27 @@ or it cannot handle some closure types, specially in function's parameters. In s create the mock manually and remove the protocol's comment as `AutoMockable`. ::: + +#### Custom annotations + +Sourcery allows us to annotate different parts of our code to guide code generation. On top of this +custom annotations have been added in `AutoMockable.stencil` to handle special cases. + +- **useSelectorName**: Method annotation used to indicate that the generated mocked properties need + to use the selector name instead of the short method name. This is specially useful when using + function overloading where we need the mocked names to also have the parameters names to + differentiate between the different mocked functions. +- **mockReceivedInvocations**: Method annotation used to indicate that we want to generate the + mocked property to store an array of the received invocations of the parameters passed each time + the function is called. + +For example: + +```swift +protocol FooProtocol { // sourcery: AutoMockable + func bar(fooParameter: String) -> Bool + func bar(anotherParameter: Int) -> Bool // sourcery: useSelectorName + func saveNumber(theNumber: Int) -> Bool // sourcery: mockReceivedInvocations + func annotateMultiple(fooParameter: String) // sourcery: useSelectorName, mockReceivedInvocations +} +``` From 9d8aaed12db8d978868606b48d42814d18a0d4e1 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Thu, 20 Nov 2025 13:39:57 -0300 Subject: [PATCH 3/5] PM-23500 Improved Sourcery docs with Claude feedback. --- docs/architecture/mobile-clients/ios/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/architecture/mobile-clients/ios/index.md b/docs/architecture/mobile-clients/ios/index.md index a73153896..f70642ef8 100644 --- a/docs/architecture/mobile-clients/ios/index.md +++ b/docs/architecture/mobile-clients/ios/index.md @@ -453,7 +453,7 @@ This makes it convenient to switch between these files or open them side-by-side [ios version](https://github.com/bitwarden/ios/blob/main/.test-simulator-ios-version)), otherwise tests may fail because of subtle differences between iOS versions. -### Mocks generation +### Mock generation We use [Sourcery](https://github.com/krzysztofzablocki/Sourcery) for automatic mock generation. @@ -472,18 +472,18 @@ protocol FooProtocol { // sourcery: AutoMockable :::info Manual generation There are some cases where the automatically generated mock does not cover the mock scenario we want -or it cannot handle some closure types, specially in function's parameters. In such cases prefer +or it cannot handle some closure types, especially in function's parameters. In such cases prefer to create the mock manually and remove the protocol's comment as `AutoMockable`. ::: #### Custom annotations -Sourcery allows us to annotate different parts of our code to guide code generation. On top of this -custom annotations have been added in `AutoMockable.stencil` to handle special cases. +Sourcery allows us to annotate different parts of our code to guide code generation. Custom +annotations have been added in `AutoMockable.stencil` to handle special cases. - **useSelectorName**: Method annotation used to indicate that the generated mocked properties need - to use the selector name instead of the short method name. This is specially useful when using + to use the selector name instead of the short method name. This is especially useful when using function overloading where we need the mocked names to also have the parameters names to differentiate between the different mocked functions. - **mockReceivedInvocations**: Method annotation used to indicate that we want to generate the From b312c120239542b4009315ef26c50e022fb29deb Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Thu, 20 Nov 2025 13:42:29 -0300 Subject: [PATCH 4/5] PM-23500 Improved grammatical errors in iOS Getting Started --- docs/getting-started/mobile/ios/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/getting-started/mobile/ios/index.md b/docs/getting-started/mobile/ios/index.md index af1e1dcb6..868644165 100644 --- a/docs/getting-started/mobile/ios/index.md +++ b/docs/getting-started/mobile/ios/index.md @@ -8,9 +8,9 @@ sidebar_position: 1 1. [Xcode](https://developer.apple.com/xcode/) (using [this](https://github.com/bitwarden/ios/blob/main/.xcode-version) version) -2. iOS & watchOS simulator runtimes installed +2. iOS and watchOS simulator runtimes installed 3. An iPhone simulator set up (check - [model](https://github.com/bitwarden/ios/blob/main/.test-simulator-device-name) & + [model](https://github.com/bitwarden/ios/blob/main/.test-simulator-device-name) and [version](https://github.com/bitwarden/ios/blob/main/.test-simulator-ios-version) to make/run snapshots) @@ -61,8 +61,8 @@ sidebar_position: 1 $ cp Scripts/post-checkout .git/hooks/ ``` - Also, if the Xcode version installed mismatches the expected one you will receive a warning when - the script finishes like this one which can help troubleshooting. + Also, if the installed Xcode version does not match the expected version, you will receive a + warning, which can help with troubleshooting. That warning looks like this: ``` 🟡 Xcode version mismatch! From e50d21588af1a5ed85e32ceb20056b0d28862146 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Thu, 20 Nov 2025 18:10:55 -0300 Subject: [PATCH 5/5] PM-23500 Addressed PR feedback --- docs/architecture/mobile-clients/ios/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/architecture/mobile-clients/ios/index.md b/docs/architecture/mobile-clients/ios/index.md index f70642ef8..1c045ed9d 100644 --- a/docs/architecture/mobile-clients/ios/index.md +++ b/docs/architecture/mobile-clients/ios/index.md @@ -472,8 +472,8 @@ protocol FooProtocol { // sourcery: AutoMockable :::info Manual generation There are some cases where the automatically generated mock does not cover the mock scenario we want -or it cannot handle some closure types, especially in function's parameters. In such cases prefer to -create the mock manually and remove the protocol's comment as `AutoMockable`. +or it cannot handle some closure types, especially in function parameters. In such cases prefer to +create the mock manually and remove the protocol's `AutoMockable` comment. ::: @@ -484,7 +484,7 @@ annotations have been added in `AutoMockable.stencil` to handle special cases. - **useSelectorName**: Method annotation used to indicate that the generated mocked properties need to use the selector name instead of the short method name. This is especially useful when using - function overloading where we need the mocked names to also have the parameters names to + function overloading where we need the mocked names to also have the parameter names to differentiate between the different mocked functions. - **mockReceivedInvocations**: Method annotation used to indicate that we want to generate the mocked property to store an array of the received invocations of the parameters passed each time